In-place singly-linked-list reversal with three pointers. Algorithm: walk once, and for each node, save next=curr.next, flip curr.next=prev, then advance prev=curr, curr=next. After one pass the list is reversed in-place with O(1) extra space. We show the pointer dance on A→B→C→D→E.
Step 2 / 12
Initial: prev=nil, curr=A (head), next=?. No node has been reversed yet. The cursor marks curr. We keep prev implicit (shown by the color of already-processed nodes turning good) because there is no “nil” slot on the list.
Step 3 / 12
Iteration 1, substep a: read next=curr.next=B. The link A→B is highlighted – that's the pointer we are about to flip. Substep b: curr.next=prev=nil. In the reversed list A becomes the new tail, so A.next=nil.
Step 4 / 12
Iteration 1, substep c: advance. prev=curr=A (now marked good, meaning already reversed), curr=next=B. A is the tail of the reversed prefix so far. One node reversed: reversed =[A], remaining =B→C→D→E.
Step 5 / 12
Iteration 2, substep a: next=curr.next=C. Substep b: curr.next=prev=A. The link B→C is being rewritten to B→A. Visually, we show the link B→C highlighted because that is the original forward pointer we are consuming; once the iteration completes the logical direction is B→A in the reversed list.
Step 6 / 12
Iteration 2, substep c: advance. prev=B, curr=C. Reversed so far: B→A, length 2. Remaining: C→D→E. Two nodes are now coloured good (already in the reversed prefix).
Step 7 / 12
Iteration 3, substep a: next=curr.next=D. Substep b: curr.next=prev=B. We flip C→D into C→B in the reversed list.
Step 8 / 12
Iteration 3, substep c: advance. prev=C, curr=D. Reversed so far: C→B→A, length 3. Remaining: D→E. Halfway through (one write per node, n writes total – O(n) time).
Iteration 4, substep c: advance. prev=D, curr=E. Reversed so far: D→C→B→A, length 4. Remaining: E alone. One more iteration.
Step 11 / 12
Iteration 5, substep a: next=curr.next=nil (E is the original tail). Substep b: curr.next=prev=D. Flip to point E→D. Substep c: advance. prev=E, curr=next=nil, loop exits. The new head is prev=E.
Step 12 / 12
Reversal complete. Traversal order from the new head: E→D→C→B→A. Cost: one pass, O(n) time, O(1) auxiliary space (three pointers: prev, curr, next). Scriba's LinkedList primitive doesn't currently expose a per-link direction flip in the DSL, so we trace the pointer moves via cursor and state recolouring; the algorithm itself is faithful frame by frame.