Dan,
As Nick said the unltimate node is not getting swapped.
But, do-while would also repeat the same mistake.
So, handle the ultimate case seperately as below:
I guess this shud work,
void reverse_list(NodePtr p)
{
NodePtr next, q=p, head=p->prev;
while (q != head)
{
next = q->next;
q->next = q->prev;
q->prev = next;
q = next;
}
next = q->next;
q->next = q->prev;
q->prev = next;
}
Cheers,
Sriram.
"Daniel" <hk******@gmail.com> wrote in message
news:2f**************************@posting.google.c om...
I need to reverse the doubly linked list with dummy node. I think the
solution is to exchange each node pointers' next and previous address.
But what's wrong in my function?
Thanks
void reverse_list(NodePtr p)
{ NodePtr next, q=p, head=p->prev;
while (q != head)
{ next = q->next;
q->next = q->prev;
q->prev = next;
q = next;
}
}