AlgoScope

Reverse Linked List

Walk the list with three pointers and flip each arrow to face the other way.

Linked list algorithms, algorithm, beginner
Saving next. 5's next now points to null.5142currheadnext
Saving next. 5's next now points to null.5142currheadnext

Singly Linked List: Reverse the list

Decision, step 2 of 11

Remember next (1), then flip 5's arrow to point back at null.

Cost

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

Recursive variant uses O(n) stack.

Before this

Variants

  • IterativeThree-pointer walk.
  • RecursiveReverse the rest

Leads to

Topics that need this one first.

Taught by the same lesson

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