Why do we need a temp variable?
Without temp, you can lose access to the current node or the remainder of the list while rewiring pointers.
LazyCoder
Practice reversing a singly linked list and see how head, temp, and prev change at every step.
Reversal is not about memorizing a pattern. It is about preserving access to the remaining nodes while you redirect the current next pointer. This page keeps the visual state and code trace in sync so the sequence is explicit.
This is one of the most common linked list interview exercises because it tests pointer discipline. If you can explain the order of assignments clearly, you usually understand the structure well enough to handle harder variants.
Without temp, you can lose access to the current node or the remainder of the list while rewiring pointers.
The original head becomes the last node, so its next pointer must end at null.