Insert at Tail
Walk to the last node and attach the new node after it.
Singly Linked List: Insert at the tail
2 is the last node: point its next at the new node 9.
Cost
- Best
- O(1)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(1)
O(1) with a tail pointer.
Before this
Related
Taught by the same lesson
Singly Linked List covers these too, in the same run.