Complete the code to start traversal from the head node.
let current = [1];Traversal of a circular linked list starts from the head node.
Complete the condition to stop traversal after one full cycle.
do {
console.log(current.data);
current = current.next;
} while (current !== [1]);Traversal stops when current comes back to the head node, completing the cycle.
Fix the error in the traversal loop to avoid infinite loop.
while (current !== [1]) { console.log(current.data); current = current.next; }
In circular linked list, loop should stop when current reaches head again to avoid infinite loop.
Fill both blanks to complete the traversal function for circular linked list.
function traverseCircularList(head) {
if (!head) return;
let current = head;
do {
console.log(current.data);
current = current.[1];
} while (current !== [2]);
}Traversal moves to the next node and stops when it reaches the head again.
Fill all three blanks to create a function that collects data from a circular linked list into an array.
function collectData(head) {
if (!head) return [];
let result = [];
let current = [1];
do {
result.push(current.[2]);
current = current.[3];
} while (current !== head);
return result;
}Start from head, push data of current node, move to next node, stop when back at head.
