401 data structures and algorithms code challenges
Extend a Linked List to allow various insertion methods.
Write the following methods for the Linked List class:
Initial List | Method Args | Resulting List |
---|---|---|
head -> [1] -> [3] -> [2] -> X | 5 | head -> [1] -> [3] -> [2] -> [5] -> X |
head -> X | 1 | head -> [1] -> X |
| Initial List | Method Args | Resulting List | |—|—|—| | head -> [1] -> [3] -> [2] -> X | 3, 5 | head -> [1] -> [5] -> [3] -> [2] -> X | | head -> [1] -> [3] -> [2] -> X | 1, 5 | head -> [5] -> [1] -> [3] -> [2] -> X | | head -> [1] -> [2] -> [2] -> X | 2, 5 | head -> [1] -> [5] -> [2] -> [2] -> X | | head -> [1] -> [3] -> [2] -> X | 4, 5 | No change, method exception |
| Initial List | Method Args | Resulting List | |—|—|—| | head -> [1] -> [3] -> [2] -> X | 3, 5 | head -> [1] -> [3] -> [5] -> [2] -> X | | head -> [1] -> [3] -> [2] -> X | 2, 5 | head -> [1] -> [3] -> [2] -> [5] -> X | | head -> [1] -> [2] -> [2] -> X | 2, 5 | head -> [1] -> [2] -> [5] -> [2] -> X | | head -> [1] -> [3] -> [2] -> X | 4, 5 | No change, method exception |
Write tests to prove the following functionality:
Write an additional method to delete a node with the given value from the linked list.