Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move to the next node in the linked list.
DSA C++
current = current[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' instead of '->' to access next node.
Using 'next' without any operator.
Using '->prev' which points to previous node.
✗ Incorrect
In C++, to access the next node pointer from a node pointer, use '->next'.
2fill in blank
mediumComplete the code to print the data of the current node.
DSA C++
std::cout << current[1] << " -> ";
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' instead of '->' to access data.
Using 'data' without any operator.
Using '->value' which is not the correct member.
✗ Incorrect
Use '->data' to access the data member of the node pointer.
3fill in blank
hardFix the error in the loop condition to traverse the linked list correctly.
DSA C++
while (current [1] nullptr) { // process node current = current->next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which assigns instead of compares.
Using '==' which stops at first node.
Using '<' which is invalid for pointers.
✗ Incorrect
The loop should continue while current is not nullptr, so use '!='.
4fill in blank
hardFill both blanks to create a loop that prints all node data followed by 'null'.
DSA C++
while (current [1] nullptr) { std::cout << current[2] << " -> "; current = current->next; } std::cout << "null" << std::endl;
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' in loop condition causing no iteration.
Using '.' instead of '->' to access data.
✗ Incorrect
Use '!=' to loop until current is nullptr and '->data' to print node data.
5fill in blank
hardFill all three blanks to create a function that prints a linked list.
DSA C++
void printList(Node* [1]) { Node* current = [2]; while (current [3] nullptr) { std::cout << current->data << " -> "; current = current->next; } std::cout << "null" << std::endl; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong parameter name.
Assigning wrong variable to current.
Using '=' instead of '!=' in loop condition.
✗ Incorrect
The function parameter is 'head', assign it to 'current', and loop while current != nullptr.
