Is My Code Correct for Floyd cycle?

i have Written my code for removal of Linked list cycle but don’t know if it is correct or not so can you check it (code - “https://ide.codingblocks.com/s/102282”) and fucntion of removal is at line - #275

You can check your code here.
https://hack.codingblocks.com/contests/c/53/471

Click on the link and you will find a question related same.
Submit it there and check if it working correct or not.

Suggestion: Read the input and output format of the question.
Let me know, if you face any problem.

i have attempted that question but getting Runtime Error . whats wrong here - “https://ide.codingblocks.com/s/102528

The logic you are applying for removing cycle is wrong.
As, you know that you are building a linear linked list.
So, there is no cycle exist structurally.
Hence, that slow-fast method would not work here.

Your function detectCycle() will always return NULL.

Suggestion:

  1. traverse the linked list linearly and at every node check if the node->next->data has already occurred in the left side of that node.
  2. if yes, then make node->next=NULL. This will remove the rest of the nodes and hence, the cycle.
  3. if not, move one node ahead and repeat the same.

Hope, this would help.