Where am i thinking wrong?

you have not created the cycle and try to find cycle
steps which you have to follow in this question

  1. first take input and mark the node from where values are start repeating
  2. create cycle
  3. detect cycle
  4. remove cycle

REFERENCE CODE

i have created the cycle, if we comment the finding cycle and removing part and then give the input and print the list, then the output is cycle but when i remove the comment then it is not running, so i guess the problem is in detecting the cycle part but can’t figure out where

your logic of findconnection() is not correct
correct way to break the cycle is

void  BreakCycle(node*head){
	node*slow=head,*fast=head->next,*temp=NULL;

	while(fast&&fast->next){
		if(slow==fast)break;
		slow=slow->next;
		fast=fast->next->next;
	}
	// if cycle not present
	if(fast==NULL||fast->next==NULL)return;

	/// now count no of nodes in loop
	int k=1;
	slow=slow->next;
	while(slow!=fast){
		k++;
		slow=slow->next;
	}

	// now point slow to head and fast to k node ahead
	slow=head;
	fast=head;
	while(k--){
		fast=fast->next;
	}
	/// move slow and fast one by one
	while(slow!=fast){
		slow=slow->next;
		fast=fast->next;
	}
	// now move only fast
	while(fast->next!=slow){
		fast=fast->next;	
	}
	fast->next=NULL;
}

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.