no this is not the way to do this
- first make cycle in linked list using given input
- and then detect and remove cycle
- at last print the new linked list(without cycle)
for step 1 use can either use map or set
int main(){
node*head=NULL;
int arr[10000]={};
int cnt=0;
int x;cin>>x;
set<int>s;
int cycle=-1;
while(x!=-1){
arr[cnt]=x;
cnt++;
s.insert(x);
if(s.size()!=cnt){
cnt--;
cycle=x;
break;
}
cin>>x;
}
for(int i=cnt-1;i>=0;i--){
head=insertatbeg(arr[i],head);
}
// Print(head);
makecycle(cycle,head);
// cout<<detectCycle(head)<<endl;
BreakCycle(head);
Print(head);
return 0;
}
now implement function used in main()
i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course