Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new node with given data.
DSA C++
Node* newNode = new Node([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using 'next' instead of data when creating the node.
Passing 'head' instead of the data value.
Using NULL as data.
✗ Incorrect
We create a new node by passing the data value to the Node constructor.
2fill in blank
mediumComplete the code to link the new node to the current head.
DSA C++
newNode->[1] = head;Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data' instead of 'next' to link nodes.
Using 'prev' which is for doubly linked lists.
Using 'value' which is not a pointer.
✗ Incorrect
The 'next' pointer of the new node should point to the current head node.
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 head->next which moves head incorrectly.
Assigning head to NULL which empties the list.
✗ Incorrect
The head should be updated to point to the new node after insertion.
4fill in blank
hardFill both blanks to complete the push function that adds a node at the front.
DSA C++
void push(Node*& head, int data) {
Node* newNode = new Node([1]);
newNode->[2] = head;
head = newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'head' as data value.
Using 'value' instead of 'next' pointer.
Swapping the order of assignments.
✗ Incorrect
We create a new node with 'data' and link its 'next' to the current head.
5fill in blank
hardFill all three blanks to complete the push function with proper node creation and linking.
DSA C++
void push(Node*& head, int data) {
Node* newNode = new Node([1]);
newNode->[2] = [3];
head = newNode;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' pointer which is not used in singly linked list.
Assigning 'head' before linking newNode.
Passing wrong variable to Node constructor.
✗ Incorrect
Create new node with 'data', set its 'next' to current 'head', then update 'head'.
