Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move to the last node in the linked list.
DSA C
while (temp->[1] != NULL) { temp = temp->next; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' instead of 'next' to move forward.
Trying to access 'data' pointer which does not link nodes.
✗ Incorrect
To traverse a linked list, we move from the current node to the next node using the 'next' pointer until we reach the last node where next is NULL.
2fill in blank
mediumComplete the code to update the second last node's next pointer to NULL after deleting the last node.
DSA C
prev->[1] = NULL; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting 'data' to NULL instead of 'next'.
Trying to set 'prev' pointer which is not used here.
✗ Incorrect
To remove the last node, the second last node's 'next' pointer must be set to NULL to mark the new end of the list.
3fill in blank
hardFix the error in the code to correctly free the last node after deletion.
DSA C
free([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Freeing 'prev' which points to the second last node.
Freeing 'head' which is the start of the list.
✗ Incorrect
The pointer 'temp' points to the last node that needs to be deleted, so we free 'temp' to release its memory.
4fill in blank
hardFill both blanks to traverse the list and keep track of the previous node.
DSA C
while (temp->next != NULL) { [1] = temp; temp = temp->[2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping 'prev' and 'temp' assignments.
Using 'temp' instead of 'next' to move forward.
✗ Incorrect
We assign 'prev' to current 'temp' before moving 'temp' to the next node to keep track of the node before the last.
5fill in blank
hardFill all three blanks to handle the case when the list has only one node and delete it.
DSA C
if (head->next == NULL) { free([1]); [2] = NULL; return [3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Freeing 'temp' which may not be initialized here.
Returning NULL literal instead of 'head' pointer.
✗ Incorrect
If only one node exists, free 'head', set 'head' to NULL, and return the updated 'head' pointer.
