Reverse Linked List
Walk the list with three pointers and flip each arrow to face the other way.
Singly Linked List: Reverse the list
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
- Iterative
- Recursive
Related
Leads to
Topics that need this one first.
Taught by the same lesson
Singly Linked List covers these too, in the same run.