Merge sorted linked lists

#include
using namespace std;
class node{
public:
int data;
node* next;
node(int d){
data=d;
next=NULL;
}
};
void insertattail(node* & root,int data){

if(root==NULL){
	root=new node(data);
	return;
}
node* temp=root;
while(temp->next!=NULL){
	temp=temp->next;

}
temp->next=new node(data);
return;

}
void print(node* head){
if(head==NULL){
return;
}
while(head->next != NULL){
cout<data<<" ";
head=head->next;
}
cout<data;
}
node merge(node a,node* b){
if(a==NULL){
return b;
}
if(b==NULL){
return a;

}
node* c;

if(a->datadata){
c=a;
c->next=merge(a->next,b);

}
else{
c=b;
c->next=merge(a,b->next);
}
return c;

}
int main() {
int t;
cin>>t;
while(t–){

node* a=NULL;

int n;
cin>>n;
while(n–){
int data;
cin>>data;

insertattail(a,data);
}
node *b =NULL;
int m;
cin>>m;
// print (a);
while(m–){
int data;
cin>>data;

insertattail(b,data);
}
// print(b);
node* c=merge(a,b);
print©;
}
return 0;
}

sample pass but not testcases

hi @kumarakash121005 code is correct just add a new line after each test case

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.