Complete the code to update the head pointer after deletion.
self.head = [1];After deleting the first node, the head should point to the next node.
Complete the code to remove the backward link from the new head.
if let Some(ref mut node) = self.head { node.[1] = None; }
The previous pointer of the new head should be None to detach the old first node.
Fix the error in the code that handles empty list after deletion.
if self.head.is_none() { self.[1] = None; }
If the list becomes empty after deletion, tail should also be None.
Fill both blanks to correctly detach the first node and update the list.
if let Some(mut old_head) = self.head.take() { self.head = old_head.[1]; if let Some(ref mut new_head) = self.head { new_head.[2] = None; } }
We move head to old_head.next and set new_head.prev to None to detach the old first node.
Fill all three blanks to complete the delete from beginning function safely.
pub fn delete_from_beginning(&mut self) {
if self.head.is_none() {
return;
}
if let Some(mut old_head) = self.head.take() {
self.head = old_head.[1];
if let Some(ref mut new_head) = self.head {
new_head.[2] = None;
} else {
self.[3] = None;
}
}
}Move head to old_head.next, set new_head.prev to None, and if list is empty, set tail to None.
