Https://ide.codingblocks.com/s/257644

why its not running correctly remove cycle

You are not forming the circular linked list correctly.
Print and check your formed linked list. It shows 1 2 3 4 5 2 3 . But it must be 1 2 3 4 5
In this question you first need to create the circular linked list. Then break it from the point where it forms the loop. Use the Floyd Cycle detection algo as taught in the course.
After breaking the loop you have to print the resulting linked list.
Say If INPUT IS 1 2 3 4 5 2 3 -1
form a linked list 1->2->3->4>5 then you see that 2 has already been visited , so connect the next pointer of 5 to 2. This way you have created the circular linked list . After that just detect the cycle, remove the cycle(using Floyd Cycle detection and removal algo), print the new linked list.
Maintain a map or a visited array…as soon as you see that a node is already visited, connect next pointer of previous node to that node.

You can refer this https://ide.codingblocks.com/s/257662 and try to understand the implementation.

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.