Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add a new node at the front of the dequeue.
DSA C#
public void AddFront(int value) {
Node newNode = new Node(value);
if (front == null) {
front = rear = newNode;
} else {
newNode.next = [1];
front.prev = newNode;
front = newNode;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Setting newNode.next to rear instead of front
Forgetting to update front.prev
Assigning newNode.next to null
✗ Incorrect
To add at the front, the new node's next should point to the current front node.
2fill in blank
mediumComplete the code to remove a node from the rear of the dequeue.
DSA C#
public int RemoveRear() {
if (rear == null) throw new InvalidOperationException("Dequeue is empty");
int value = rear.data;
rear = rear.prev;
if (rear != null) {
rear.[1] = null;
} else {
front = null;
}
return value;
}Attempts:
3 left
💡 Hint
Common Mistakes
Setting rear.prev to null instead of rear.next
Not updating front when rear becomes null
Returning wrong value
✗ Incorrect
After moving rear back, its next pointer should be set to null to detach the removed node.
3fill in blank
hardFix the error in the code to add a node at the rear of the dequeue.
DSA C#
public void AddRear(int value) {
Node newNode = new Node(value);
if (rear == null) {
front = rear = newNode;
} else {
rear.next = newNode;
newNode.[1] = rear;
rear = newNode;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Setting newNode.next instead of newNode.prev
Not updating rear pointer
Assigning newNode.front or newNode.data incorrectly
✗ Incorrect
The new node's prev pointer should point to the old rear node.
4fill in blank
hardFill both blanks to correctly remove a node from the front of the dequeue.
DSA C#
public int RemoveFront() {
if (front == null) throw new InvalidOperationException("Dequeue is empty");
int value = front.data;
front = front.[1];
if (front != null) {
front.[2] = null;
} else {
rear = null;
}
return value;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next to move front
Not clearing front.prev after removal
Not updating rear when list becomes empty
✗ Incorrect
To remove front, move front to front.next and set new front.prev to null.
5fill in blank
hardFill all three blanks to create a method that checks if the dequeue is empty.
DSA C#
public bool IsEmpty() {
return [1] == null && [2] == null && [3] == 0;
}Attempts:
3 left
💡 Hint
Common Mistakes
Checking size instead of count
Checking only front or rear but not both
Using incorrect variable names
✗ Incorrect
The dequeue is empty if front and rear are null and count is zero.
