Complete the code to check if the list is empty before deletion.
if head [1] { return; }
We check if head is None to know if the list is empty.
Complete the code to find the node before the one to delete.
while current.next.as_ref().unwrap().data != [1] { current = current.next.as_mut().unwrap(); }
We look for the node whose next node has the data equal to the key to delete.
Fix the error in updating the head when deleting the head node.
if current.next.as_ref().unwrap().data == head.as_ref().unwrap().data { head = [1]; }
When deleting the head, update head to the next node after the current's next node.
Fill both blanks to correctly remove the node from the list.
current.next = [1]; current.next.as_mut().unwrap().next = [2];
Set current's next to skip the deleted node, and update the next pointer to head to maintain circularity.
Fill all three blanks to complete the function that deletes a node by key.
fn delete_node(head: &mut Option<Box<Node>>, key: i32) {
if head [1] { return; }
let mut current = head.as_mut().unwrap();
while current.next.as_ref().unwrap().data != [2] {
current = current.next.as_mut().unwrap();
}
if current.next.as_ref().unwrap().data == head.as_ref().unwrap().data {
head = [3];
}
current.next = current.next.as_ref().unwrap().next.clone();
}Check if head is None, find the node before the key, and update head to the next node after the deleted one.
