Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the doubly linked list is empty before deletion.
DSA C#
if (head == [1]) { return; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if head equals tail instead of null.
Using 'this' keyword incorrectly.
✗ Incorrect
We check if head is null to know if the list is empty before deleting.
2fill in blank
mediumComplete the code to move the tail pointer to the previous node before deletion.
DSA C#
tail = tail.[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' instead of 'prev'.
Trying to assign tail to head.
✗ Incorrect
To delete from the end, we move tail to its previous node.
3fill in blank
hardFix the error in setting the new tail's next pointer to null after deletion.
DSA C#
if (tail != null) { tail.[1] = null; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting tail.prev to null instead of tail.next.
Setting tail to null.
✗ Incorrect
After moving tail back, we set tail.next to null to mark the end.
4fill in blank
hardFill both blanks to correctly handle the case when the list has only one node.
DSA C#
if (head == tail) { head = [1]; tail = [2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head or tail to themselves instead of null.
Not handling the single-node case.
✗ Incorrect
When only one node exists, deleting it sets both head and tail to null.
5fill in blank
hardFill all three blanks to complete the DeleteFromEnd method of a doubly linked list.
DSA C#
public void DeleteFromEnd() {
if (head == [1]) {
return;
}
if (head == tail) {
head = [2];
tail = [3];
return;
}
tail = tail.prev;
tail.next = null;
}Attempts:
3 left
💡 Hint
Common Mistakes
Not returning after setting head and tail to null.
Incorrectly checking for empty list.
Not updating tail.next to null.
✗ Incorrect
The method checks if the list is empty, then if it has one node, sets head and tail to null, else moves tail back and disconnects the last node.
