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 in the method.
Confusing the node variable with the data value.
✗ Incorrect
The constructor of Node takes the data value to store in the node. Here, 'data' is the correct variable.
2fill in blank
mediumComplete the code to link the new node to the current head of the list.
DSA C#
newNode.[1] = head;Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is for doubly linked lists.
Using an undefined property name.
✗ Incorrect
In a singly linked list, each node points to the next node using the 'next' reference.
3fill in blank
hardFix the error in updating the head pointer to the new node.
DSA C#
head = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Assigning head to newNode.next which skips the new node.
Assigning head to null which empties the list.
✗ Incorrect
After pushing, the head should point to the new node itself, not its next.
4fill in blank
hardFill both blanks to complete the push method that adds a new node at the start.
DSA C#
public void Push(int data) {
Node newNode = new Node([1]);
newNode.[2] = head;
head = newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' for singly linked list.
Passing wrong variable to node constructor.
✗ Incorrect
The new node is created with 'data' and its 'next' points to the current head.
5fill in blank
hardFill all three blanks to complete the push method with correct variable and pointer assignments.
DSA C#
public void Push(int [1]) { Node [2] = new Node([1]); [2].next = head; head = [2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Confusing parameter name with node variable name.
✗ Incorrect
The method parameter is 'data', the new node variable is 'newNode', and all references use 'newNode'.
