Skip to content

Instantly share code, notes, and snippets.

@rahulkmr
Created February 7, 2010 07:32
Show Gist options
  • Save rahulkmr/297283 to your computer and use it in GitHub Desktop.
Save rahulkmr/297283 to your computer and use it in GitHub Desktop.
struct node
{
int info;
struct node *next;
};
int cycle(struct node *head)
{
struct node *slow, *fast;
if (head == NULL)
return 0;
slow = head;
fast = head->next;
while (slow != fast && slow != NULL) {
slow = slow->next;
if (fast->next->next != NULL)
fast = fast->next->next;
}
if (slow == fast)
return 1;
else
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment