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 head; }
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 if head equals 1 or head itself.
✗ Incorrect
We check if head is NULL to know if the list is empty.
2fill in blank
mediumComplete the code to delete the head node when it matches the value.
DSA C
if (head->data == value) { struct Node* temp = head; head = head->[1]; free(temp); return head; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using head->prev which does not exist in singly linked list.
Using head->data or head->value which are data fields, not pointers.
✗ Incorrect
To delete the head node, we move head to head->next.
3fill in blank
hardFix the error in the loop condition to find the node before the one to delete.
DSA C
while (current->next != NULL && current->next->data [1] value) { current = current->next; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' causes loop to stop immediately if first node matches.
Using '>' or '<' is incorrect for equality check.
✗ Incorrect
We continue while current->next->data is not equal to value to find the node before target.
4fill in blank
hardFill both blanks to correctly remove the target node from the list.
DSA C
if (current->next != NULL) { struct Node* temp = current->[1]; current->[2] = temp->next; free(temp); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev which does not exist in singly linked list.
Using data or value which are data fields, not pointers.
✗ Incorrect
We use current->next to access and remove the target node.
5fill in blank
hardFill all three blanks to complete the delete function returning the updated head.
DSA C
struct Node* deleteNode(struct Node* head, int value) {
struct Node* current = head;
if (head == [1]) return head;
if (head->data == value) {
struct Node* temp = head;
head = head->[2];
free(temp);
return head;
}
while (current->next != NULL && current->next->data != value) {
current = current->next;
}
if (current->next != NULL) {
struct Node* temp = current->next;
current->next = temp->[3];
free(temp);
}
return head;
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev pointer which does not exist in singly linked list.
Not updating head when deleting the first node.
✗ Incorrect
Check for empty list with NULL, move head to head->next, and link current->next to temp->next.
