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
Using 0 instead of NULL for pointer comparison.
Checking head == head which is always true.
✗ Incorrect
In C, an empty list's head pointer is NULL. Checking head == NULL confirms the list is empty.
2fill in blank
mediumComplete the code to traverse the list to find the node with the given value.
DSA C
struct Node* current = head; while (current != NULL && current->data != [1]) { current = current->next; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with head or NULL instead of the value.
Using current->next instead of current->data.
✗ Incorrect
We compare current->data with the value to find the node to delete.
3fill in blank
hardFix the error in updating the previous node's next pointer when deleting the current node.
DSA C
if (current->prev != NULL) { current->prev->[1] = current->next; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Updating prev pointer instead of next.
Assigning to data or head which are incorrect.
✗ Incorrect
We must update the previous node's next pointer to skip the current node.
4fill in blank
hardFill both blanks to correctly update the next node's prev pointer and handle head update.
DSA C
if (current->next != NULL) { current->next->[1] = current->prev; } if (current == [2]) { head = current->next; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using next instead of prev for backward link.
Not updating head when deleting the first node.
✗ Incorrect
The next node's prev pointer must point to current's prev. If current is head, update head to next.
5fill in blank
hardFill the blanks to free the node and complete the delete function.
DSA C
free([1]); [2] = NULL; return;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Freeing head instead of current.
Returning a value in a void function.
✗ Incorrect
We free the current node, set current to NULL to avoid a dangling pointer.
