Complete the code to start traversing the linked list from the head node.
let mut current = [1];We start traversing a linked list from the head node, which is the first node.
Complete the code to move to the next node in the linked list during traversal.
current = current.unwrap()[1];To move forward in a singly linked list, we use the next pointer of the current node.
Fix the error in the loop condition to correctly traverse until the end of the linked list.
while current [1] None { println!("{}", current.as_ref().unwrap().value); current = current.unwrap().next; }
The loop should continue while current is not None, meaning there are still nodes to visit.
Fill both blanks to create a loop that prints all node values separated by arrows and ends with null.
while current [1] None { print!("{} -> ", current.as_ref().unwrap().value); current = current.unwrap()[2]; } println!("null");
The loop runs while current is not None, and moves to the next node each time.
Fill all three blanks to build a function that traverses and prints the linked list values with arrows and ends with null.
fn print_list(mut current: Option<Box<Node>>) {
while current [1] None {
print!("{} -> ", current.as_ref().unwrap().[2]);
current = current.unwrap()[3];
}
println!("null");
}The function loops while current is not None, prints the node's value, then moves to the next node.
