Insert at Position
Walk to the node before the gap, then relink it and the new node in order.
Singly Linked List: Insert at index 2
Create 9 and point its next at 4 first, so nothing is lost.
Cost
- Best
- O(1)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(1)
Before this
Related
Taught by the same lesson
Singly Linked List covers these too, in the same run.