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 head or tail instead of the value.
Assigning nullptr instead of the value.
✗ Incorrect
We create a new node with the given value to insert it at the end.
2fill in blank
mediumComplete the code to handle the empty list case by pointing newNode to itself.
DSA C++
if (head == nullptr) { newNode->next = [1]; head = newNode; return; }
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to nullptr breaks the circular property.
Using head or tail which may be null.
✗ Incorrect
In a circular linked list with one node, the node points to itself.
3fill in blank
hardFix the error in the loop that finds the last node before head.
DSA C++
Node* temp = head; while (temp->next != [1]) { temp = temp->next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for nullptr instead of head.
Using newNode or tail which are not defined here.
✗ Incorrect
In a circular linked list, the last node points back to head, so we loop until next is head.
4fill in blank
hardFill both blanks to insert newNode at the end and maintain circular links.
DSA C++
temp->next = [1]; newNode->next = [2];
Attempts:
3 left
💡 Hint
Common Mistakes
Setting newNode->next to nullptr breaks the circle.
Not updating temp->next to newNode.
✗ Incorrect
The last node's next points to newNode, and newNode's next points back to head.
5fill in blank
hardFill all three blanks to complete the insert function for circular linked list.
DSA C++
void insertEnd(Node*& head, int value) {
Node* newNode = new Node([1]);
if (head == nullptr) {
newNode->next = [2];
head = newNode;
return;
}
Node* temp = head;
while (temp->next != [3]) {
temp = temp->next;
}
temp->next = newNode;
newNode->next = head;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using nullptr instead of newNode or head.
Not looping until temp->next equals head.
✗ Incorrect
Create newNode with value, point newNode to itself if list empty, loop until last node points to head.
