You are viewing a single comment's thread. Return to all comments →
bool has_cycle(SinglyLinkedListNode* head) { if(!head) return false; SinglyLinkedListNode* ptr1=head; SinglyLinkedListNode* ptr2=head;
while(ptr1->next!=NULL||ptr1!=NULL){ ptr2=ptr2->next; ptr1=ptr1->next->next; if(ptr1==ptr2) return true; }
return false;} this is my code. exactly similar. but it gives segmentation error. please Help!
Cycle Detection
You are viewing a single comment's thread. Return to all comments →
bool has_cycle(SinglyLinkedListNode* head) { if(!head) return false; SinglyLinkedListNode* ptr1=head; SinglyLinkedListNode* ptr2=head;
return false;} this is my code. exactly similar. but it gives segmentation error. please Help!