Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
We need to store the next pointer of the current node in temp before swapping pointers.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting head to temp->next causes wrong head assignment.
Not updating head leads to unchanged list start.
✗ Incorrect
After the loop, temp points to the last processed node, so head should point to temp->prev.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The loop should continue while current is not NULL to traverse all nodes.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing prev and next pointers causes incorrect reversal.
Using data instead of pointers causes errors.
✗ Incorrect
We save current->next in temp and assign current->prev to current->next to swap pointers.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up prev and next pointers in assignments.
Not moving current correctly causes infinite loop.
✗ Incorrect
We save current->next in temp, assign current->prev to current->next, and move current to current->prev.
