Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node for enqueue operation.
DSA C#
Node newNode = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'null' instead of the value for the new node.
Using 'head' or 'tail' which are pointers, not the data.
✗ Incorrect
We create a new node with the given value to enqueue it into the linked list queue.
2fill in blank
mediumComplete the code to check if the queue is empty before enqueue.
DSA C#
if (tail == [1]) { head = newNode; tail = newNode; } else { tail.next = newNode; tail = newNode; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if tail equals head instead of null.
Assigning tail to newNode before checking.
✗ Incorrect
If tail is null, the queue is empty, so both head and tail point to the new node.
3fill in blank
hardFix the error in the enqueue method to link the new node correctly.
DSA C#
tail.[1] = newNode; tail = newNode;Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is for doubly linked lists.
Assigning to 'head' or 'value' which are incorrect.
✗ Incorrect
The 'next' pointer of the current tail should point to the new node.
4fill in blank
hardFill both blanks to complete the enqueue method for linked list queue.
DSA C#
public void Enqueue(int value) {
Node newNode = new Node(value);
if (tail == [1]) {
head = newNode;
tail = newNode;
} else {
tail.[2] = newNode;
tail = newNode;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' instead of null for empty check.
Using 'prev' instead of 'next' for linking.
✗ Incorrect
Check if tail is null to detect empty queue, then link new node using 'next' pointer.
5fill in blank
hardFill all three blanks to implement enqueue operation correctly.
DSA C#
public void Enqueue(int [1]) { Node newNode = new Node([2]); if (tail == [3]) { head = newNode; tail = newNode; } else { tail.next = newNode; tail = newNode; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for parameter and node value.
Checking if tail equals head instead of null.
✗ Incorrect
Parameter name and node value use 'value'; check if tail is null for empty queue.
