Reverse Linked List

easy

Reverse a singly linked list in-place using three pointers

Reverse Linked List

Key Insight

Three pointers (prev, curr, next) walk through the list, flipping each arrow backward

Step 1Setup
curr
1
2
3
4
5
null

Initialize prev = null, curr = head. We will flip each arrow from curr to prev.

1 / 6
Practice the Code

Step-by-Step Walkthrough: Reverse Linked List

Three pointers (prev, curr, next) walk through the list, flipping each arrow backward

  1. Setup

    Initialize prev = null, curr = head. We will flip each arrow from curr to prev.

  2. Reverse First Arrow

    Save next = 2. Point 1→null. Move prev to 1, curr to 2.

  3. Reverse Second Arrow

    Save next = 3. Point 2→1. Move prev to 2, curr to 3.

  4. Reverse Third Arrow

    Save next = 4. Point 3→2. Move prev to 3, curr to 4.

  5. Reverse Fourth Arrow

    Save next = 5. Point 4→3. Move prev to 4, curr to 5.

  6. Done — List Reversed

    Point 5→4. curr becomes null, prev is the new head.