can anyone help why my code is not breaking the cycle,pls tell where is the problem in my code
Circular ll not able to brreak the cycle
The logic you are using to break the cycle is wrong. We don’t have to use slow and fast pointer approach in this.
node *temp = head;
node *prev, *curr;
while(temp!=NULL)
{
curr = temp->next;
prev = NULL;
while(curr!=NULL)
{
if(temp->data==curr->data)
{
prev->next = NULL;
print(head);
return 0;
}
prev = curr;
curr = curr->next;
}
temp = temp->next;
}
Check out this piece of code for breaking the cycle and tell me if you are able to understand 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.