Skip to content

Instantly share code, notes, and snippets.

@guojh
Created October 10, 2012 06:09
Show Gist options
  • Save guojh/3863445 to your computer and use it in GitHub Desktop.
Save guojh/3863445 to your computer and use it in GitHub Desktop.
typedef struct list_node
{
struct list_node *next;
} list_node, *plist;
plist find_circle(plist head)
{
int count, scount, ncount;
plist p, sp;
count = 1;
p = sp;
scount = count;
sp = p;
while(1) {
ncount = scount * 2;
while(p != sp && count < ncount) {
p = p->next;
count++;
}
if(p == sp)
return p;
sp = p;
scount = count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment