To reverse a list in place, walk it with three pointers: prev, curr, and next. At each step save curr->next, point curr backward at prev, and advance. When curr becomes NULL, prev is the new head. It runs in O(n) time and O(1) extra space.
next remembers the rest of the list before the link is overwritten.
Flipping curr->next makes each node point backward.
The old head ends up last with next == NULL.
Edge Cases & Pitfalls
Check these before relying on Reversing a Linked List in real programs.
lose
Flipping before saving
If you set curr->next = prev before saving next, you lose the rest of the list.
head
Forgetting to update head
The caller must replace its head with the returned pointer.
Remember
Key Takeaways
Save, flip, advance.
O(n) time, O(1) space.
Return the new head.
One line: To reverse a list in place, walk it with three pointers: prev, curr, and next.
Frequently Asked Questions
Iterate with prev, curr, and next pointers, flipping each node's next to point at prev, then return prev as the new head.
Yes, but it uses O(n) stack space. The iterative version is preferred for long lists.
Continue with "C Doubly Linked Lists" next. Nodes with prev and next pointers allow walking both ways. The C Linked Lists hub lists every topic in order.