0
Q:

find out if a linked list contains a loop

int detectLoop(struct Node* list) 
{ 
    struct Node *slow_p = list, *fast_p = list; 
  
    while (slow_p && fast_p && fast_p->next) { 
        slow_p = slow_p->next; 
        fast_p = fast_p->next->next; 
        if (slow_p == fast_p) { 
            return 1; 
        } 
    } 
    return 0; 
} 
1

New to Communities?

Join the community