Help with doubly linked list ordering
Hi,
This is not the typical " I can't reverse a doubly linked list " post.
It actually does reverse the order. But I have one issue.
Let's say the list is:
When it prints it in reverse order, it displays:
But when it prints it in reverse again, it reversing again back to normal:
And if I do reverse again, it's back to:
My question is, is this how a doubly linked list is supposed to work?
Thanks
BTW, here's the code to my reverse method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
void linkedList::reverse()
{
node* ptr = top;
while (ptr != NULL) {
node *tmp = ptr->next;
ptr->next = ptr->prev;
ptr->prev = tmp;
if (tmp == NULL) {
bottom = top;
top = ptr;
}
ptr = tmp;
}
}
|
Last edited on
is this how a doubly linked list is supposed to work? |
Why wouldn't it work that way? Why would you expect a method called "reverse" to do anything other than reverse the order of the list?
Last edited on
Ok thanks, I was just asking to make sure.
Topic archived. No new replies allowed.