Practice Discrete Math

Algorithms / Linked List Reversal

Least You Need to Know: Reversing a Linked List with Prev, Current, and Next

Linked-list reversal is the interview archetype for pointer discipline: keep track of what was before, what you are on, and what comes next. The core invariant is that one prefix has already been reversed while the remaining suffix is still untouched.

The least you need to know

Key notation

prev head of the already reversed prefix
current node currently being processed
next_node saved successor before redirecting current.next

Tiny worked example

  • Start with `prev = null`, `current = head`.
  • Save `next_node = current.next`.
  • Set `current.next = prev`, then move `prev = current` and `current = next_node`.
  • When `current` becomes null, `prev` is the new head of the reversed list.

Common mistakes

How to recognize this kind of problem

Start practice