[I]My Doubly linked list doesnt work when i try to display using backward/reverse traversal...
Will you please help me....[/I]
[IMG]http://www.withfriendship.com/user/images/616/1vijay.jpg[/IMG]
[I]My Doubly linked list doesnt work when i try to display using backward/reverse traversal...
Will you please help me....[/I]
[IMG]http://www.withfriendship.com/user/images/616/1vijay.jpg[/IMG]
The symptom reported by — forward traversal fine but reverse traversal failing — usually means the list's prev pointers or the tail/head bookkeeping are not being maintained. 's snark about a null dereference is a useful hint: a NULL where a prev pointer is expected is the most common cause. 's request to post code is also correct: concrete snippets make the bug obvious.
A short checklist to rule out the usual faults:
head is initialized to NULL and nodes are allocated on the heap (not as local stack variables).next and prev appropriately (including when inserting at the head or tail).tail pointer or find the tail first by following next until NULL, then follow prev to traverse backward.A minimal reverse-print pattern in C looks like:
Node *p = head;
if (p) {
while (p->next) p = p->next; // move to tail
while (p) {
printf("%d\n", p->data);
p = p->prev;
}
} Debugging tips: instrument the list builders to print pointer values and verify the invariant "if node->next != NULL then node->next->prev == node". Add assertions around critical updates. Run the program under Valgrind to catch invalid reads/writes (Valgrind). For a standard implementation to compare against, see the doubly linked list guide (GeeksforGeeks doubly linked list tutorial).
Jump to Post— John A 1,896And don't bother posting any code. We all have psychic powers which allow us to see into your mind and your computer and can tell you where your problem lies. In this case, you're dereferencing a null pointer on line 34.
And don't bother posting any code. We all have psychic powers which allow us to see into your mind and your computer and can tell you where your problem lies. In this case, you're dereferencing a null pointer on line 34.
:icon_wink:
Well, you just have to step forward and post something relevant to the problem(s).
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.