Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA Rust
let new_node = Box::new(Node { value: val, next: [1] });Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to Some(val) instead of None.
Trying to assign the value directly to next.
✗ Incorrect
When creating a new node for enqueue, its next pointer should be None because it will be the last node.
2fill in blank
mediumComplete the code to update the tail's next pointer to the new node.
DSA Rust
self.tail.as_mut().unwrap().next = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the node's value instead of the node itself.
Assigning None which breaks the link.
✗ Incorrect
The tail's next pointer should point to the new node wrapped in Some to link it.
3fill in blank
hardFix the error in updating the tail pointer to the new node.
DSA Rust
self.tail = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Assigning new_node directly without Some.
Wrapping new_node again in Box::new causing double boxing.
✗ Incorrect
The tail pointer should be updated to Some(new_node) because tail is an Option>.
4fill in blank
hardFill both blanks to handle the empty queue case when enqueueing.
DSA Rust
if self.head.is_none() { self.head = [1]; self.tail = [2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning new_node directly without Some.
Assigning None which leaves the queue empty.
✗ Incorrect
When the queue is empty, both head and tail should point to the new node wrapped in Some.
5fill in blank
hardFill all three blanks to complete the enqueue function updating pointers correctly.
DSA Rust
let new_node = Box::new(Node { value: val, next: None });
if self.tail.is_some() {
self.tail.as_mut().unwrap().next = [1];
}
self.tail = [2];
if self.head.is_none() {
self.head = [3];
}Attempts:
3 left
💡 Hint
Common Mistakes
Using new_node directly without Some.
Cloning new_node causing ownership errors.
Assigning None which breaks the links.
✗ Incorrect
The tail's next pointer should be Some(new_node), then tail updated to Some(new_node), and if head is None, set head to Some(new_node).
