i dont know why this code is not passing all the test cases ,i can not even find error in logic
#include<bits/stdc++.h>
using namespace std;
struct node
{
int info;
node *next;
};
node *head1,*head2,*ptr,*New1,*New2,*temp,*ptr1,*ptr2,*dummy,*head3,*dup;
/*int removeduplicates(node* head)
{
ptr=head;
while(ptr!=NULL && ptr->next!=NULL)
{
ptr1=ptr;
while(ptr1->next!=NULL)
{
if(ptr->info==ptr1->next->info)
{
dup=ptr1->next;
ptr1->next=ptr1->next->next;
delete dup;
}
else
ptr1=ptr1->next;
}
ptr=ptr->next;
}
return 0;
}
*/
void traverse(node* head3)
{
ptr=head3;
if(head3==NULL)
return;
while(ptr!=NULL)
{
cout<<ptr->info<<" ";
//cout<<" ";
ptr=ptr->next;
}
}
node* merge(node* h1, node* h2)
{
if (!h1)
return h2;
if (!h2)
return h1;
// start with the linked list
// whose head data is the least
if (h1->info <= h2->info)
{
h1->next = merge(h1->next, h2);
return h1;
}
else if(h1->info > h2->info) {
h2->next = merge(h1, h2->next);
return h2;
}
}
int main()
{
int t;
cin>>t;
while(t–)
{
int n1,n2,i,val,val1,val2,choice;
//cout<<“enter the no of nodes u want to insert\n”;
cin>>n1;
for(i=1;i<=n1;i++)
{
//cout<<“enter the val u want to insert\n”;
cin>>val1;
if(i==1)
{
New1=new node;
New1->info=val1;
New1->next=NULL;
head1=New1;
}
else
{
New1->next=new node;
New1=New1->next;
New1->info=val1;
New1->next=NULL;
}
}
// removeduplicates(head1);
cin>>n2;
for(i=1;i<=n2;i++)
{
// cout<<“enter the val u want to insert\n”;
cin>>val2;
if(i==1)
{
New2=new node;
New2->info=val2;
New2->next=NULL;
head2=New2;
}
else
{
New2->next=new node;
New2=New2->next;
New2->info=val2;
New2->next=NULL;
}
}
// removeduplicates(head2);
head3 = merge(head1,head2);
traverse(head3);
cout<<endl;
//cout<<endl;
}
return 0;
}