Complete the code to initialize the previous pointer to null.
let prev = [1];We start reversing by setting prev to null because the new tail will point to null.
Complete the code to store the next node before changing links.
let next = current.[1];We save current.next in next to not lose the rest of the list when reversing.
Fix the error in reversing the link by assigning the correct pointer.
current.next = [1];To reverse the link, current.next must point to prev, the previous node.
Fill both blanks to update pointers for the next iteration.
prev = [1]; current = [2];
After reversing the link, move prev to current and current to next to continue.
Fill all three blanks to complete the iterative reverse function.
function reverseList(head: ListNode | null): ListNode | null {
let prev = [1];
let current = head;
while (current !== null) {
let next = current.[2];
current.[3] = prev;
prev = current;
current = next;
}
return prev;
}The function starts with prev = null. Inside the loop, it saves current.next in next, then reverses the link by setting current.next = prev. Finally, it moves prev and current forward.
