//Note: Cycle may be generated any node in Linked list , So this problem can be solved by Floyd's cycle finding algorithm
// C program to detect loop in a linked list using Floyd's cycle finding algorithm
int detectcycleinLL(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)
{
printf("Found Loop");
return 1;
}
}
return 0;
}