Created
October 10, 2012 06:09
-
-
Save guojh/3863445 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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