A. The printf statement is missing a newline character
B. The pointer curr should start from head, not tail
C. The code should use curr = curr->next instead of curr = curr->prev
D. The loop condition should check curr != NULL, not curr->next != NULL
Solution
Step 1: Analyze loop condition for backward traversal
Backward traversal moves using prev pointer until curr becomes NULL.
Step 2: Identify incorrect condition
Checking curr->next != NULL is wrong; it should be curr != NULL to avoid null pointer access.
Final Answer:
The loop condition should check curr != NULL, not curr->next != NULL -> Option D
Quick Check:
Loop until curr is NULL in backward traversal [OK]
Hint: Check curr != NULL in loops, not curr->next for backward traversal [OK]
Common Mistakes:
Using next pointer condition in backward traversal
Starting from head instead of tail
Ignoring null pointer checks
5. Given a doubly linked list with nodes containing integers, write a function to print the list forward and then backward without using extra space. Which approach correctly achieves this?
hard
A. Traverse from head to tail printing data, then traverse from tail to head printing data
B. Traverse from head to tail printing data twice
C. Traverse from tail to head printing data, then traverse from head to tail printing data
D. Traverse from head to tail printing data, then reverse the list and print forward again
Solution
Step 1: Understand traversal without extra space
Use existing next and prev pointers to traverse forward and backward.
Step 2: Identify correct approach
Traverse from head to tail printing data, then traverse from tail to head printing data correctly traverses forward from head to tail, then backward from tail to head printing data without modifying list.
Final Answer:
Traverse from head to tail printing data, then traverse from tail to head printing data -> Option A
Quick Check:
Use head and tail pointers for forward and backward traversal [OK]
Hint: Print forward from head, backward from tail without changing list [OK]
Common Mistakes:
Reversing list unnecessarily
Printing forward twice
Using extra space like arrays or stacks
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.