Complete the code to define a struct for a doubly linked list node with a value field.
struct Node<T> {
value: T,
prev: Option<Box<Node<T>>>,
[1]: Option<Box<Node<T>>>,
}The next field points to the next node in the doubly linked list.
Complete the code to initialize an empty doubly linked list struct with head and tail pointers.
struct DoublyLinkedList<T> {
head: Option<Box<Node<T>>>,
[1]: Option<Box<Node<T>>>,
}The tail field points to the last node in the doubly linked list.
Fix the error in the method to create a new node with a given value.
impl<T> Node<T> {
fn new(value: T) -> Self {
Node {
value,
prev: None,
[1]: None,
}
}
}The next pointer should be initialized to None when creating a new node.
Fill both blanks to implement the constructor for an empty doubly linked list.
impl<T> DoublyLinkedList<T> {
fn new() -> Self {
DoublyLinkedList {
[1]: None,
[2]: None,
}
}
}The constructor initializes both head and tail to None for an empty list.
Fill the blanks to implement a method that checks if the doubly linked list is empty.
impl<T> DoublyLinkedList<T> {
fn is_empty(&self) -> bool {
self.[1].is_none()
&& self.[2].is_none()
}
}head or tail.next instead of tail.The method checks if head and tail are both None.
