Getting a run error in one test case

In my code all the test cases are being passed and in one test case it is showing run error.Please help what me with the issue.

The code is https://ide.codingblocks.com/s/613986

check for this testcas
3 4 5 6
and 6 connected to 4

now cycle is detected in this case so check =1 you break at node3 both slow and fast is at node 3

and then before below loop you again point slow to head(3)
now you move slow but slow->next will never we equal to head and you stuck in loop

Modified code