Find Loop

bool find_loop(node *head)
{
    node *p1, *p2;
    p1 = p2 = head;
 
    while (p1 != NULL && p1->next != NULL) {
        p1 = p1->next->next;
        p2 = p2->next;
        if (p1 == p2) 
            return true;
    }
 
    return false;
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License