C++ Linked List Reverse Function Triggers Infinite Loop

Within the function reverseList:

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;
}

Leave a Comment