not getting accepted…dont know why
hereis the code–
#include<bits/stdc++.h>
using namespace std;
class node{
public:
long long int data;
node* next;
node(long long int x){
data=x;
next=NULL;
}
};
node* insert(node* head,long long int data){
node* temp=new node(data);
node* h;
h=head;
while(h!=NULL&&h->next!=NULL)
h=h->next;
if(h==NULL){
h=temp;
head=h;
}
else
h->next=temp;
return head;
}
node* merge(node* &head1,node* &head2){
if(head1==NULL){
return head2;
}
if(head2==NULL)
return head1;
node* temp;
if((head1->data)<(head2->data)){
temp=head1;
temp->next=merge(head1->next,head2);
}
else if((head1->data)>(head2->data)){
temp=head2;
temp->next=merge(head1,head2->next);
}
return temp;
}
int main(){
long long int t;
cin>>t;
while(t--){
long long int n;
cin>>n;
node *head1=NULL,*head2=NULL;
long long int x;
for(long long int i=0;i<n;i++){
cin>>x;
head1=insert(head1,x);
}
long long int m;
cin>>m;
for(long long int i=0;i<m;i++){
cin>>x;
head2=insert(head2,x);
}
//cout<< head1->data<<endl;
node *head;
head=merge(head1,head2);
while(head!=NULL){
cout<<head->data<<" ";
head=head->next;
}
cout<<endl;
}
return 0;
}