Why is the code giving run time error even though i have dry run it

it is because u have to actually create a cycle in the input
the input simply puts numbers as 1 2 3 4 1 so on
these are just numbers u are not creating a cycle
u have to create a cycle
u can use this
void makeCycle(node *&head){
node *i=head;
node *prev;
while(i!=NULL){
node *j=head;
while(j!=i){
if(j->data==i->data){
prev->next=j;
return;
}
j=j->next;
}
prev=i;
i=i->next;
}
}
to make a cycle

1 Like

ok got it…