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 a variable name that is not defined like 'value' or 'item'.
Forgetting to pass any argument to the Node constructor.
✗ Incorrect
The new node should be created with the given 'data' value.
2fill in blank
mediumComplete the code to check if the position to insert is at the head (position 1).
DSA C++
if (pos == [1]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if pos == 0 instead of 1.
Using 'head' as a position value.
✗ Incorrect
Position 1 means inserting at the head of the list.
3fill in blank
hardFix the error in the loop that moves to the node before the insertion position.
DSA C++
for (int i = 1; i < [1] - 1 && temp != nullptr; i++) { temp = temp->next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not declared in the function.
Using 'index' or 'count' which are undefined here.
✗ Incorrect
The variable 'pos' is used to represent the insertion position in the code.
4fill in blank
hardFill both blanks to correctly update pointers when inserting in the middle.
DSA C++
newNode->next = temp->[1]; temp->[2] = newNode;
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' for these pointers.
Mixing up which pointer to update first.
✗ Incorrect
The new node's next pointer should point to temp's next node, and temp's next pointer should point to the new node.
5fill in blank
hardFill both blanks to correctly update the previous pointers after insertion.
DSA C++
if (newNode->next != nullptr) { newNode->next->[1] = newNode; } newNode->[2] = temp;
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing prev and next pointers.
Not checking if newNode->next is nullptr before updating.
✗ Incorrect
The next node's prev pointer should point to newNode, newNode's prev pointer should point to temp.
