Circular linked list

We are given a linked list which contains a cycle. Detect that cycle and break it. Print the linked list after removing the cycle.

Input Format
The first line contains space separated integers. The integers are such that all the values are distinct but the value start repeating once the cycle gets completed. The list of integers given ends when -1 is input.

Constraints
n < 10^5 where n is the length of list without the cycle

Output Format
Output single line containing space separated integers representing the list

Sample Input
1 2 3 4 5 2 3 -1
Sample Output
1 2 3 4 5

solution link: https://ide.codingblocks.com/s/294190

shows segmentation fault
what is wrong in the code?

You just keep taking inputs in the same manner as you did in the others(i.e. insertion at the tail) until you get an element which is already present in the list , in such case you need to check wheather the further elements are same if yess then point the last node to the matching node , else keep taking input .

code:

error in print
image