C++ Linked List Reverse Function Triggers Infinite Loop

Within the function reverseList:
[sourcecode]node *reverseList(node *h)
{
node *p, *q, *r;
p = h->next;
q = h;
r = NULL;
while (p)
{
r = q;
q = p;
p = p->next;
q->next = r;
}
h = q;
return h;
}[/sourcecode]

Leave a Comment