Cycle detection and removal in linked list


this is my code please tell the correct code…i am getting wrong answer…pleaase also tell how to delete the cycle…i know how to detect the cycle but i dont know how to delete it …please correct the code or provide the solution and also explain it

@lovish2552


This is the updated code. You had done an incorrect implementation of the Floyd’s algorithm. When fast becomes equal to slow, you set fast = head, and then move the two pointers towards each other. When slow->next == fast->next, we have arrived at the point where the cycle lies. Setting slow->next breaks the cycle.
Dry run it on paper and you will be able to understand it.
If my answer is able to answer your doubt, please mark the doubt as resolved.