Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with the given data.
DSA C#
Node newNode = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not defined like 'value' or 'item'.
Forgetting to pass any argument to the Node constructor.
✗ Incorrect
The new node should be created with the given data variable named 'data'.
2fill in blank
mediumComplete the code to link the new node's next pointer to the current head.
DSA C#
newNode.[1] = head;Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' for the forward link.
Using an undefined property like 'link' or 'pointer'.
✗ Incorrect
The new node's next pointer should point to the current head node.
3fill in blank
hardFix the error in setting the previous pointer of the old head node.
DSA C#
if (head != null) head.[1] = newNode;
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the old head's next pointer instead of prev.
Using an incorrect property name like 'pointer' or 'link'.
✗ Incorrect
The old head's previous pointer should point back to the new node.
4fill in blank
hardFill both blanks to update the head pointer and the new node's previous pointer.
DSA C#
head = [1]; newNode.[2] = null;
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head to old head instead of new node.
Setting newNode.next to null instead of newNode.prev.
✗ Incorrect
The head should be updated to the new node, and the new node's prev pointer should be null as it is the first node.
5fill in blank
hardFill all three blanks to complete the InsertAtBeginning method for a doubly linked list.
DSA C#
public void InsertAtBeginning(int data) {
Node newNode = new Node([1]);
newNode.[2] = head;
if (head != null) head.[3] = newNode;
newNode.prev = null;
head = newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up next and prev pointers.
Not updating head to the new node.
Forgetting to set newNode.prev to null.
✗ Incorrect
The method creates a new node with data, sets its next to head, updates old head's prev to new node, sets new node's prev to null, and updates head.
