You are viewing a single comment's thread. Return to all comments →
bool has_cycle(SinglyLinkedListNode* head) { SinglyLinkedListNode* p=head; SinglyLinkedListNode* q=head; if(p==NULL) return false; while(p!=NULL && p->next!=NULL) { q=q->next; p=p->next->next; if(p==q) return true; } return false; }
Seems like cookies are disabled on this browser, please enable them to open this website
Cycle Detection
You are viewing a single comment's thread. Return to all comments →