Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the list is empty before deletion.
DSA C
if (head == [1]) { printf("List is empty\n"); return; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if head == 0 instead of NULL
Checking tail instead of head
Using an uninitialized pointer
✗ Incorrect
We check if head is NULL to determine if the list is empty.
2fill in blank
mediumComplete the code to move to the last node in the list.
DSA C
struct Node* temp = head; 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 traverse forward
Checking data instead of next pointer
Using head inside the loop incorrectly
✗ Incorrect
We use the next pointer to move forward to the last node.
3fill in blank
hardFix the error in updating the previous node's next pointer after deleting the last node.
DSA C
if (temp->prev != NULL) { temp->prev->[1] = NULL; } else { head = NULL; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting prev pointer to NULL instead of next
Setting head pointer inside the if block incorrectly
Not handling the case when temp->prev is NULL
✗ Incorrect
We set the previous node's next pointer to NULL to mark it as the new end.
4fill in blank
hardFill both blanks to correctly free the last node and update the list.
DSA C
struct Node* toDelete = temp; temp = temp->prev; free([1]); temp->[2] = NULL;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Freeing temp instead of toDelete
Setting prev pointer to NULL instead of next
Not updating pointers after free
✗ Incorrect
We free the node stored in toDelete and set temp's next pointer to NULL.
5fill in blank
hardFill all three blanks to handle deletion when only one node exists.
DSA C
if (head->[1] == NULL) { free(head); head = [2]; tail = [3]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking prev instead of next
Setting head or tail to head instead of NULL
Not freeing the node before resetting pointers
✗ Incorrect
If the only node's next is NULL, free it and set head and tail to NULL.
