AlgoScope

Insert at Head

Point the new node at the old head, then move head onto it. Nothing else shifts.

Linked list algorithms, algorithm, beginner
New node 9 created. Its next points to 5.95142head
New node 9 created. Its next points to 5.95142head

Singly Linked List: Insert at the head

Step, step 2 of 4

Create the node 9 and point its next at the old head, 5.

How singly linked list works

Cost

Best
O(1)
Average
O(1)
Worst
O(1)
Space
O(1)

Leads to

Topics that need this one first.

Taught by the same lesson

Singly Linked List covers these too, in the same run.