RUN ERROR ON SUBMISSION OTHERWISE CORRECT ANSWER

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;
node
head2=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;

}

Hey friend please share your code using ide.codingblocks.com

In your print function, after while loop add endl for output format moreover you will get a correct output but you are making a new linked list name antim. You have to make a or b the existing linked list to your new linked list . This can be done using recursion. Whereas as far as your this code. Try to run this
1
5
1 3 5 7 9
6
2 4 6 8 10 12
You will get an output of 1 2 3 4 5 6 7 8 9 12
Which is wrong.

thankyou so much !!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.