Bird
0
0
DSA Cprogramming~10 mins

Delete Node by Value in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ANULL
B0
Chead
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of NULL for pointer comparison.
Checking if head equals 1 or head itself.
2fill in blank
medium

Complete 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'
Aprev
Bnext
Cvalue
Ddata
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.
3fill in blank
hard

Fix 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'
A!=
B==
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' causes loop to stop immediately if first node matches.
Using '>' or '<' is incorrect for equality check.
4fill in blank
hard

Fill 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'
Anext
Bprev
Cdata
Dvalue
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.
5fill in blank
hard

Fill 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'
ANULL
Bnext
Dprev
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.