can u tell me, is it required to write full code or function for the cycle detection
My code is:-
#include<bits/stdc++.h>
using namespace std;
struct node{
int info;
struct node *next;
};
typedef struct node node;
node * check(node *start,int data){
if(start==NULL)
return NULL;
node *p =start;
while(p->next!=NULL){
if(p->info==data){
return p;
}
p=p->next;
}
return p;
}
node *insert(node *start,int data){
node *temp,*p;
temp = (node *)malloc(sizeof(node));
temp->info = data;
temp->next = NULL;
if(start == NULL){
start = temp;
return start;
}
p = start;
while(p->next!=NULL){
p = p->next;
}
p->next = check(start,data);
return start;
}
int main() {
// your code goes here
node *start = NULL;
int data;
cin>>data;
while(data!=-1){
start = insert(start,data);
}
node *fast = start->next;
node *slow = start;
node *prev = slow;
while(fast->next!=NULL || fast!=NULL){
prev = slow;
fast = fast->next->next;
slow = slow->next;
if(fast == slow){
prev->next = NULL;
break;
}
}
return 0;
}