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);
nodetemp=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;
}
nodec;
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–)
{
nodehead1=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);
}
nodenewHead=merge2LL(head1,head2);
printList(newHead);
}
return 0;
}