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,21 @@
|
||||
SinglyLinkedList: operations, errors and the links followed (hops)
|
||||
==================================================================
|
||||
|
||||
addLast(10) -> [10]
|
||||
addLast(30) -> [10, 30]
|
||||
add(1, 20) -> [10, 20, 30]
|
||||
addFirst(5) -> [5, 10, 20, 30]
|
||||
remove(2) -> removed 20, list [5, 10, 30]
|
||||
removeLast() -> removed 30, list [5, 10]
|
||||
removeFirst() -> removed 5, list [10]
|
||||
indexOf(10) -> 0 indexOf(99) -> -1
|
||||
|
||||
empty.removeFirst() throws NoSuchElementException: list is empty
|
||||
list.get(5) throws IndexOutOfBoundsException: index 5, size 1
|
||||
|
||||
Links followed (hops) per operation, on a list that already holds n values:
|
||||
n | addFirst | addLast no tail | addLast + tail | get(n/2) | indexOf(last) | removeFirst | removeLast
|
||||
10 | 0 | 36 | 0 | 5 | 9 | 0 | 8
|
||||
100 | 0 | 4851 | 0 | 50 | 99 | 0 | 98
|
||||
1000 | 0 | 498501 | 0 | 500 | 999 | 0 | 998
|
||||
("addLast no tail" and "addLast + tail" are the total hops to build the whole list of n by repeated addLast.)
|
||||
Reference in New Issue
Block a user