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 NULL instead of data when creating the node.
Using head or tail instead of data.
✗ Incorrect
We create a new node by passing the data value to the Node constructor.
2fill in blank
mediumComplete the code to check if the list is empty.
DSA C++
if ([1] == NULL) {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking tail instead of head.
Checking newNode or data which are unrelated.
✗ Incorrect
The list is empty if the head pointer is NULL.
3fill in blank
hardFix the error in updating the tail pointer after insertion.
DSA C++
tail = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Assigning tail to head or NULL.
Assigning tail to tail->next which may be NULL.
✗ Incorrect
After inserting at the end, tail should point to the new node.
4fill in blank
hardFill both blanks to link the new node at the end of the list.
DSA C++
tail->[1] = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev instead of next.
Assigning tail->next to head instead of newNode.
✗ Incorrect
The current tail's next pointer should point to the new node.
5fill in blank
hardFill all three blanks to complete the tail insertion function.
DSA C++
void insertAtEnd(Node*& head, Node*& tail, int data) {
Node* [1] = new Node(data);
if (head == NULL) {
head = [2];
tail = [3];
} else {
tail->next = newNode;
tail = newNode;
}
}
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for newNode.
Assigning tail instead of newNode to head.
✗ Incorrect
Create newNode, set head and tail to newNode if list empty.
