void removecycle(node *&head)
{
if (detectCycle(head))
{
node *slow = head;
node *fast = head;
while (fast != NULL && fast->next != NULL)
{
slow = slow->next;
fast = fast->next->next;
if (slow == fast)
{
return;
}
}
node *prev = NULL;
//now bring slow again to the head;
slow = head;
while (slow != fast)
{
slow = slow->next;
prev = fast;
fast = fast->next;
}
//set the previous node’s next to null and hence breaking the cycle
prev->next = NULL;
}
}
Check my remove cycle function is correct or not
And instead of this return break should be written.