Merge linked list ,why is it not passing its passing test case

#include<bits/stdc++.h>
using namespace std;
class node{
public:
int data;
node *next;

};
void insert(node **n,int d){
if(n==NULL){
n=new node;
return;
}
node * temp=new node();
node * last=n;
temp->data=d;
temp->next=NULL;
if(n==NULL){
n=temp;
return;
}
while(last->next!=NULL)
last=last->next;
last->next=temp;
return;
}
void print(node
n){
while(n!=NULL){
cout<<" "<data;
n=n->next;
}
}
node
merge(node
a, node
b){
if(a==NULL){
return b;
}else if(b==NULL){
return a;
}
node*c;
if(a->data < b->data){
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;
    {
        node*res=NULL;

int n;cin>>n;

node *head=NULL;int f;
for(int i=0;i<n;i++)cin>>f,insert(&head,f);
int n1;cin>>n1;
node *head1=NULL;int f1;
for(int i=0;i<n1;i++)cin>>f1,insert(&head1,f1);

res=merge(head,head1);
print (res);
cout<<endl;
}
}

Check now ->

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.