1. New tail
prev starts null — it becomes the new list's end.
let prev = nullTyporithm · easy
Step 1 of 8 · intro card
Linked Lists
Walk the list flipping each next pointer backward, tracking prev, curr, and a saved next.
Reversing a list means making every node point to its predecessor instead of its successor.
You must save the next node before flipping, or the rest of the list is lost.
When curr reaches null, prev sits on the old tail — the new head.
Save next before flipping.
Flip curr.next to prev.
prev ends as the new head.
function reverseList(head) {
let prev = null;
let curr = head;
while (curr !== null) {
const next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
return prev;
}Connect each part of the code to the concept before you type.
prev starts null — it becomes the new list's end.
let prev = nullStore the next node before overwriting the pointer.
const next = curr.nextPoint the current node backward to prev.
curr.next = prevMove prev forward to the node just reversed.
prev = currprev ends on the old tail, which is the new head.
return prevRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.