You are viewing a single comment's thread. Return to all comments →
bool has_cycle(Node* head) { Node *s=head,*f=head; while(s && f->next && f->next->next) { s=s->next; f=f->next->next; if(s==f) { return 1; } } return 0;
Seems like cookies are disabled on this browser, please enable them to open this website
Linked Lists: Detect a Cycle
You are viewing a single comment's thread. Return to all comments →
bool has_cycle(Node* head) { Node *s=head,*f=head; while(s && f->next && f->next->next) { s=s->next; f=f->next->next; if(s==f) { return 1; } } return 0;