Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6r9iSyHu5qSJMzH2n
15 lines
829 B
Plaintext
15 lines
829 B
Plaintext
Reversing 1 -> 2 -> 3 -> 4 with three pointers
|
|
==============================================
|
|
|
|
start prev=null cur=1 reversed: null still to do: 1 -> 2 -> 3 -> 4 -> null
|
|
pass 1 prev=1 cur=2 reversed: 1 -> null still to do: 2 -> 3 -> 4 -> null
|
|
pass 2 prev=2 cur=3 reversed: 2 -> 1 -> null still to do: 3 -> 4 -> null
|
|
pass 3 prev=3 cur=4 reversed: 3 -> 2 -> 1 -> null still to do: 4 -> null
|
|
pass 4 prev=4 cur=null reversed: 4 -> 3 -> 2 -> 1 -> null still to do: null
|
|
|
|
recursive version on the same list: 4 -> 3 -> 2 -> 1 -> null
|
|
|
|
iterative, 1,000,000 nodes: first value after reversing = 999999 (no problem)
|
|
recursive, 1,000 nodes on a 1 MB thread stack: ok
|
|
recursive, 1,000,000 nodes on a 1 MB thread stack: StackOverflowError
|