find_loop(Node *startnode){ Node *slow = *fast1 = *fast2 = startnode; while(slow){ fast1 = fast2->next; fast2 = fast1->next; /* check if slow node matches with any */ if (slow == fast1 || slow == fast2) return(TRUE); slow = slow->next; } return (FALSE);} }
find_loop(Node *startnode)
ReplyDelete{
Node *slow = *fast1 = *fast2 = startnode;
while(slow){
fast1 = fast2->next;
fast2 = fast1->next;
/* check if slow node matches with any */
if (slow == fast1 || slow == fast2)
return(TRUE);
slow = slow->next;
}
return (FALSE);
}
}