Merge two sorted linked lists

Why does this code fail all the test cases?

#include<bits/stdc++.h>
using namespace std;

class node{
public:
int data;
node*next;

node(int d)
{
    data=d;
    next=NULL;
}

};

void inserT(node*&head,int d)
{
if(head==NULL)
{
head=new node(d);
return;
}
noden=new node(d);
node
temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=n;
n->next=NULL;
}

nodemerge2LL(nodea,nodeb)
{
if(a==NULL)
{
return b;
}
if(b==NULL)
{
return a;
}
node
c;
if(a->data < b->data)
{
c=a;
c->next=merge2LL(a->next,b);
}
else
{
c=b;
c->next=merge2LL(a,b->next);
}
return c;
}

void printList(noden)
{
while(n!=NULL)
{
cout<data<<" ";
n=n->next;
}
return;
}
int main()
{
int t;
cin>>t;
while(t–)
{
node
head1=NULL;
nodehead2=NULL;
int n1;
cin>>n1;
for(int j=1;j<=n1;j++)
{
int d;
cin>>d;
inserT(head1,d);
}
int n2;
cin>>n2;
for(int j=1;j<=n2;j++)
{
int d;
cin>>d;
inserT(head2,d);
}
node
newHead=merge2LL(head1,head2);
printList(newHead);
}
return 0;
}

hello @brinda_dabhi

print output for each test case in seprate line.

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.