Insert at Head
Point the new node at the old head, then move head onto it. Nothing else shifts.
Result · step 2 of 4Singly Linked List: Insert at the head
Create the node 9 and point its next at the old head, 5.
What you will see
The new node appears, its arrow attaches to the old head, then HEAD jumps to it.
Cost
| Best | O(1) |
|---|---|
| Average | O(1) |
| Worst | O(1) |
| Space | O(1) |
How you work with it here
play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next, try operations in any order.
Screen readers: Each node announces its value and what it points to; each step announces the pointer change ("node 3 now points to node 5").
Reduced motion: Pointer arrows redraw in place with a brief emphasis instead of animating the detach and reattach.
Before this
Taught by the same lesson
Singly Linked List covers these too, in the same run.