Insert at Head
Point the new node at the old head, then move head onto it. Nothing else shifts.
Singly Linked List: Insert at the head
Create the node 9 and point its next at the old head, 5.
Cost
- Best
- O(1)
- Average
- O(1)
- Worst
- O(1)
- Space
- O(1)
Before this
Related
Leads to
Topics that need this one first.
Taught by the same lesson
Singly Linked List covers these too, in the same run.