Watch the pointers flip one link at a time to reverse a linked list from 10 to 60. Worked example, a recursive version, O(n) time and O(1) extra space.
About this algorithm
Reversing a singly linked list turns every next pointer round so the old tail becomes the new head. It takes one walk and three pointers: prev, the part already reversed; curr, the node being flipped; and next, a saved link to the rest of the list so it is not lost when curr changes direction.
Reach for this whenever a problem needs a list read backwards without extra memory: checking whether a list is a palindrome (reverse the second half and compare), adding two numbers stored one digit per node, or reversing every group of k nodes. It is the in-place way. If memory is not a concern, copying the values into an array or onto a stack and reading them back is simpler but costs O(N) extra space. A doubly linked list rarely needs reversing at all, since you can walk it backwards from the tail.
prev starts as null, because the old head will become the last node and must point to nothing. curr starts at the head.
next = curr.next. Without this, the next line would cut curr off from everything after it.
curr.next = prev. This is the only line that changes the list; everything else moves the pointers along.
prev = curr, then curr = next. Loop while curr is not null. When curr becomes null, prev sits on the old tail, which is the new head: return prev.
The page loads six nodes, 10, 20, 30, 40, 50, 60. Start with prev at null and curr at 10. Round 1: save 20, point 10 at null, then move on, so prev is 10 and curr is 20. Round 2: save 30, point 20 back at 10; prev is 20 and curr is 30. Rounds 3 to 6 do the same for 30, 40, 50 and 60. After round 6, prev is 60 and curr is null, so the loop ends. Six arrows were turned, one per node, and the list now reads 60, 50, 40, 30, 20, 10, with 10 pointing at null.
Recursion reverses the rest of the list first, then hooks the current node onto its end: call reverse(head.next), set head.next.next = head and head.next = null, and return the new head passed up from the bottom. It is shorter to write, but it uses one call stack frame per node, so it needs O(N) space and can overflow on a very long list.
Time: each of the N nodes is visited once and has exactly one pointer changed. Space: three pointers no matter how long the list is, so O(1).