Bird
0
0
DSA Cprogramming~10 mins

Reverse a Doubly Linked List 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 swap the next and prev pointers of the current node.

DSA C
void reverse(struct Node** head_ref) {
    struct Node* temp = NULL;
    struct Node* current = *head_ref;
    while (current != NULL) {
        temp = current->[1];
        current->prev = current->next;
        current->next = temp;
        current = current->prev;
    }
}
Drag options to blanks, or click blank then click option'
Aprev
Bhead
Cnext
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using current->prev instead of current->next causes incorrect traversal.
Swapping pointers without saving next node leads to losing the list.
2fill in blank
medium

Complete the code to update the head pointer after reversing the list.

DSA C
if (temp != NULL) {
    *head_ref = temp->[1];
}
Drag options to blanks, or click blank then click option'
Anext
Bprev
Cdata
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head to temp->next causes wrong head assignment.
Not updating head leads to unchanged list start.
3fill in blank
hard

Fix the error in the while loop condition to correctly traverse the list.

DSA C
while ([1] != NULL) {
    // swapping pointers
}
Drag options to blanks, or click blank then click option'
Acurrent
B*head_ref
Ctemp
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Using temp instead of current causes infinite loop or no traversal.
Using *head_ref instead of current causes incorrect condition.
4fill in blank
hard

Fill both blanks to correctly swap pointers and move to the next node.

DSA C
temp = current->[1];
current->prev = current->[2];
Drag options to blanks, or click blank then click option'
Anext
Bprev
Cdata
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing prev and next pointers causes incorrect reversal.
Using data instead of pointers causes errors.
5fill in blank
hard

Fill all three blanks to complete the reverse function correctly.

DSA C
void reverse(struct Node** head_ref) {
    struct Node* temp = NULL;
    struct Node* current = *head_ref;
    while (current != NULL) {
        temp = current->[1];
        current->prev = current->[2];
        current->next = temp;
        current = current->[3];
    }
    if (temp != NULL) {
        *head_ref = temp->prev;
    }
}
Drag options to blanks, or click blank then click option'
Anext
Bprev
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up prev and next pointers in assignments.
Not moving current correctly causes infinite loop.