normally gives correct answer but giving run error on submission
#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;
}
}
node* mergee(nodea,nodeb){
node* antim = NULL;
node* travel = NULL;
if(a->data > b->data){
travel=antim = b;
b= b->next;
}
else{
travel = antim = a;
a = a->next;
}
while(a!=NULL && b!=NULL){
if(b->data < a->data){
travel->next = b;
b= b->next;
travel = travel->next;
}
else{
travel->next = a;
a = a->next;
travel = travel->next;
}
}
//IT IS STILL NOT FINISHED THERE IS ONE THING LEFT YET
if(b==NULL){
while(a!=NULL){
travel->next = a;
a=a->next;
}
}
else{
while(b!=NULL){
travel->next = b;
b = b->next;
}
}
return antim;
}
int main() {
int n;
cin>>n;
while(n–){
int num1;
cin>>num1;
nodehead1=NULL;
for(int i=0;i<num1;i++){
int key;
cin>>key;
input(head1,key);
}
int num2;
cin>>num2;
nodehead2=NULL;
for(int i=0;i<num2;i++){
int key;
cin>>key;
input(head2,key);
}
node*ultimate_head = mergee(head1,head2);
print(ultimate_head);
cout<<endl;
}
return 0;
}