In-Place Linked List Reversal

Reverse a linked list or sublist by re-wiring next pointers without allocating additional nodes.

Reverse a linked list or sublist by re-wiring next pointers without allocating additional nodes.

After processing node i, all nodes up to and including i are reversed relative to their original order; prev marks the new tail of the reversed segment.

Three pointers (prev, current, next) are sufficient to re-wire any node: save next, point current back to prev, advance both.

A single O(n) pass re-wires all n pointers in place with no heap allocation.