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 { data: [1], next: None });Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' or 'tail' instead of the value.
Setting data to None which is invalid.
✗ Incorrect
We create a new node with the given value to insert at the end.
2fill in blank
mediumComplete the code to handle the empty list case by pointing new_node.next to itself.
DSA Rust
new_node.next = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to None breaks circularity.
Pointing next to head or tail when list is empty.
✗ Incorrect
In an empty circular list, the new node points to itself.
3fill in blank
hardFix the error in updating the tail's next pointer to the new node.
DSA Rust
unsafe { (*tail).next = Some([1]); }Attempts:
3 left
💡 Hint
Common Mistakes
Assigning Box directly causes type mismatch.
Assigning None breaks the list.
✗ Incorrect
We must convert new_node to a raw pointer before assigning to tail.next.
4fill in blank
hardFill both blanks to update the new node's next pointer and the tail pointer.
DSA Rust
new_node.next = Some([1]); tail = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Setting new_node.next to tail breaks circularity.
Not updating tail pointer after insertion.
✗ Incorrect
The new node points to head, and tail updates to new node's raw pointer.
5fill in blank
hardFill all three blanks to complete the insert_at_end function for circular linked list.
DSA Rust
fn insert_at_end(head: &mut Option<*mut Node>, value: i32) {
let mut new_node = Box::new(Node { data: value, next: None });
if head.is_none() {
new_node.next = Some([1]);
*head = Some([2]);
} else {
let tail = unsafe { find_tail(*head.unwrap()) };
new_node.next = *head;
unsafe { (*tail).next = Some([3]); }
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Assigning Box directly instead of raw pointer.
Not updating head or tail pointers properly.
✗ Incorrect
All blanks require converting new_node to a raw pointer to maintain circular links.
