Complete the code to start traversal from the head node.
let current = [1];Traversal of a linked list starts from the head node.
Complete the code to move to the next node during traversal.
current = current[1];To move forward in a singly linked list, assign current to current.next.
Fix the error in the loop condition to traverse until the end of the list.
while (current [1] null) { console.log(current.value); current = current.next; }
The loop should continue while current is not null, so use !=.
Fill both blanks to create a function that prints all values in the linked list.
function printList([1]: ListNode | null): void { let current = [2]; while (current != null) { console.log(current.value); current = current.next; } }
The function takes a parameter named node and starts traversal from it by assigning it to current.
Fill all three blanks to create a function that collects values from the linked list into an array.
function listValues([1]: ListNode | null): number[] { const values: number[] = []; let [2] = [3]; while (current != null) { values.push(current.value); current = current.next; } return values; }
The function parameter is node. We declare current and assign it to node to start traversal.
