Add linked-list module: singly and doubly lists with measured costs, reverse, middle, Floyd cycle detection, merge and 5 more interview problems, the 2015 menu programs and a doubly-list bug they exposed (15 tests, 15 transcripts)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6r9iSyHu5qSJMzH2n
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
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
|
||||
Reference in New Issue
Block a user