#include
using namespace std;
class node{
public:
int data;
node* next;
node(int d){
data=d;
next=NULL;
}
};
void insertattail(node &head ,int data){
node * n=new node(data);
if(head==NULL){
head=n;
return ;
}
node temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=n;
}
void print(node *head){
while(head!=NULL){
cout<data<<" ";
head=head->next;
}
}
void builtlist(node &head,int n){
int data ;
cin>>data ;
insertattail(head,data);
n–;
while(n>0){
cin>>data;
insertattail(head,data);
n–;
}
}
node merge(node *a,node *b){
if(a==NULL){
return b;
}
if(b==NULL){
return a;
}
node *c;
if(a->data>b->data){
c=b;
c->next=merge(a,b->next);
}
else{
c=a;
c->next=merge(a->next,b);
}
return c;
}
int main() {
int t;
cin>>t;
int n1,n2;
for(int i=0;i<t;i++){
node * head1=NULL;
node * head2=NULL;
cin>>n1;
builtlist(head1,n1);
cin>>n2;
builtlist(head2,n2);
node* c=merge(head1,head2);
print(c);
cout<<endl;
}
return 0;
}
whats the problem in this code