Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given value.
DSA C#
Node newNode = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'null' instead of the value.
Using 'head' or 'next' which are references, not values.
✗ Incorrect
We create a new node by passing the value to the Node constructor.
2fill in blank
mediumComplete the code to check if the list is empty before inserting.
DSA C#
if (head == [1]) { head = newNode; }
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing head to newNode instead of null.
Using 'next' which is a pointer, not the list head.
✗ Incorrect
If head is null, the list is empty, so we set head to the new node.
3fill in blank
hardFix the error in the loop to find the last node.
DSA C#
Node current = head; while (current.[1] != null) { current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking current.head or current.value which are not pointers.
Using newNode which is unrelated here.
✗ Incorrect
We check current.next to find the last node whose next is null.
4fill in blank
hardFill both blanks to link the new node at the end of the list.
DSA C#
current.[1] = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head or value instead of newNode.
Using wrong pointer names.
✗ Incorrect
Set current.next to newNode to link the new node at the end.
5fill in blank
hardFill all three blanks to complete the tail insert method.
DSA C#
public void InsertAtEnd(int [1]) { Node newNode = new Node([2]); if (head == null) { head = newNode; return; } Node current = head; while (current.[3] != null) { current = current.next; } current.next = newNode; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for parameter and newNode.
Checking or assigning wrong pointers.
✗ Incorrect
The method parameter is 'value', newNode is created with 'value', and we traverse using 'next'.
