Bird
0
0
DSA Cprogramming~10 mins

Reverse a Singly Linked List Iterative 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 initialize the previous pointer to NULL before starting the reversal.

DSA C
struct Node* reverseList(struct Node* head) {
    struct Node* prev = [1];
    struct Node* current = head;
    struct Node* next = NULL;
    while (current != NULL) {
        next = current->next;
        current->next = prev;
        prev = current;
        current = next;
    }
    return prev;
}
Drag options to blanks, or click blank then click option'
ANULL
Bhead
Ccurrent
Dnext
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing prev to head instead of NULL causes incorrect links.
Using uninitialized pointers leads to runtime errors.
2fill in blank
medium

Complete the code to update the next pointer to the next node in the list inside the loop.

DSA C
while (current != NULL) {
    [1] = current->next;
    current->next = prev;
    prev = current;
    current = next;
}
Drag options to blanks, or click blank then click option'
Aprev
Bhead
Ccurrent
Dnext
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning prev or current instead of next causes loss of list nodes.
Not saving next before changing links breaks the list.
3fill in blank
hard

Fix the error in the return statement to return the new head of the reversed list.

DSA C
return [1];
Drag options to blanks, or click blank then click option'
Acurrent
Bprev
Chead
Dnext
Attempts:
3 left
💡 Hint
Common Mistakes
Returning head returns the original list, not reversed.
Returning current or next leads to NULL or incomplete list.
4fill in blank
hard

Fill both blanks to complete the while loop condition and update current pointer correctly.

DSA C
while ([1] != NULL) {
    next = current->next;
    current->next = prev;
    prev = current;
    current = [2];
}
Drag options to blanks, or click blank then click option'
Acurrent
Bprev
Cnext
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Using prev in the loop condition causes infinite loop.
Updating current to prev or head breaks traversal.
5fill in blank
hard

Fill all three blanks to complete the iterative reversal function correctly.

DSA C
struct Node* reverseList(struct Node* head) {
    struct Node* prev = [1];
    struct Node* current = head;
    struct Node* next = NULL;
    while (current != [2]) {
        next = current->next;
        current->next = [3];
        prev = current;
        current = next;
    }
    return prev;
}
Drag options to blanks, or click blank then click option'
ANULL
Bhead
Cprev
Dcurrent
Attempts:
3 left
💡 Hint
Common Mistakes
Using head instead of NULL for prev initialization.
Wrong loop condition causes infinite or no loop.
Setting current->next to wrong pointer breaks the list.