Skip to content
DSA Visualizerpreview

Reverse a linked list

Turn every arrow around with three pointers and no extra memory.

O(n) time · O(1) space

Values1, 2, 3, 4, 5

Reverse the list 1 → 2 → 3 → 4 → 5. prev starts at null and curr at the head.

Nodes 1, 2, 3, 4, 5; 1 points to 2; 2 points to 3; 3 points to 4; 4 points to 5; 5 points to null.
  • compare
  • swap or write
  • settled

1 / 17

Speed

Space play · ← → step · Home End jump · drag the strip to scrub