Pattern visualizer
Three-pointer reversal
Flipping a node's arrow overwrites the only link to the rest of the list, so the rest of the chain must be saved off before you make the cut — that's the entire reason a third pointer exists. Walk forward one node at a time: stash what comes next, point the current node backward into the already-reversed prefix, then slide forward and repeat, so prev trails the reversed part while curr is the node currently being flipped. Reach for it whenever you must reverse links with O(1) extra space. Animated on: Reverse the singly linked list 1->2->3->4 in place.
Linked List
Input: 1->2->3->4, every arrow points right. Goal: flip all arrows so 4 becomes the head.
1FUNCTION reverse(head):2 prev = nothing (the reversed part is empty)3 curr = head4 WHILE curr is not empty:5 next = the node after curr6 make curr point backward to prev7 prev = curr8 curr = next9 END WHILE10 RETURN prev11END FUNCTION
← / → step · space play · Home restart