Bird
0
0
DSA Cprogramming~10 mins

Traversal Forward and Backward 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 move the pointer forward in a singly linked list.

DSA C
current = current[1];
Drag options to blanks, or click blank then click option'
A->next
B->prev
C.next
D.prev
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.next' instead of '->next' in pointer access.
Using 'prev' pointer which does not exist in singly linked list.
2fill in blank
medium

Complete the code to move the pointer backward in a doubly linked list.

DSA C
current = current[1];
Drag options to blanks, or click blank then click option'
A->prev
B->next
C.prev
D.next
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.prev' instead of '->prev' in pointer access.
Using 'next' pointer to move backward.
3fill in blank
hard

Fix the error in the traversal code to move forward in a singly linked list.

DSA C
while (current != NULL) {
    printf("%d -> ", current->data);
    current = current[1];
}
printf("NULL\n");
Drag options to blanks, or click blank then click option'
A->prev
B->next
C.next
D.prev
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' pointer which does not exist in singly linked list.
Using '.' operator instead of '->' for pointer access.
4fill in blank
hard

Fill both blanks to traverse backward and print data in a doubly linked list.

DSA C
while (current != NULL) {
    printf("%d -> ", current->data);
    current = current[1];
}
printf("NULL\n");

// To move backward:
current = tail;
while (current != NULL) {
    printf("%d -> ", current->data);
    current = current[2];
}
printf("NULL\n");
Drag options to blanks, or click blank then click option'
A->next
B->prev
C.prev
D.next
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' operator instead of '->'.
Mixing up next and prev pointers.
5fill in blank
hard

Fill all three blanks to create a function that prints a doubly linked list forward and backward.

DSA C
void printList(struct Node* head, struct Node* tail) {
    struct Node* current = head;
    while (current != NULL) {
        printf("%d -> ", current[1]);
        current = current[2];
    }
    printf("NULL\n");

    current = tail;
    while (current != NULL) {
        printf("%d -> ", current[3]);
        current = current->prev;
    }
    printf("NULL\n");
}
Drag options to blanks, or click blank then click option'
A->data
B->next
D->prev
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' instead of '->' for pointer access.
Using wrong pointer to move forward or backward.