all test case has not pass. please correct it.
Cycle Detection and Removal in Linked list problem
bool floydCycleRemoval(Node *head)
{
/* Code here */
if(head==NULL)return false;
Node*slow=head,*fast=head->next;
while(fast&&fast->next){
if(slow==fast)break;
slow=slow->next;
fast=fast->next->next;
}
// if cycle not present
if(fast==NULL||fast->next==NULL)return false;
if (fast->next == head)
{
fast->next = NULL;
return true;
}
fast=fast->next;
slow=head;
/// move slow and fast one by one
while(slow->next!=fast->next){
slow=slow->next;
fast=fast->next;
}
fast->next=NULL;
return true;
}
this is correct way to do it
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.