why is it giving runtime error, plz help debugging
#include
using namespace std;
class node{
public:
int data;
node* next;
node(int key){
data = key;
next= NULL;
}
};
void input(node*&head , int key){
if(head == NULL){
head = new node(key);
}
else{
node * emp = head;
while(emp -> next != NULL){
emp = emp ->next;
}
node * temp = new node(key);
emp->next = temp;
}
return;
}
void print (node * head){
while(head!=NULL){
cout<<head ->data<<" ";
head = head->next;
}
}
int main(){
node* head = NULL;
int len;
cin>>len;
for(int i=0;i<len;i++){
int key;
cin>>key;
input(head,key);
}
int end;
cin>>end;
nodeslow = head;
node fast = head;
while(endβ){
slow = slow->next;
fast = fast->next->next;
}
while(fast!=NULL && fast->next != NULL){
fast=fast->next;
slow=slow->next;
}
node* temp = slow->next;
node* head2 = temp;
slow->next = NULL;
while(temp->next != NULL){
temp = temp->next;
}
temp->next = head;
print(head2);
return 0;
}
