Sir the code is compiling and giving right output on gdb compiler, but here it is failing to compile.
#include
using namespace std;
class node
{
public:
int data;
node *next;
node(int d)
{
data=d;
next=NULL;
}
};
void Display(node *p)
{
while(p!=NULL)
{
cout<data<<" ";
p=p->next;
}
cout<<endl;
}
node * Create(node *head,int n)
{
int ele;
cin>>ele;
head=new node(ele);
node *last=head;
for(int i=0;i<n-1;i++)
{
cin>>ele;
node *t=new node(ele);
last->next=t;
last=t;
}
return head;
}
node * merge(node *a,node *b)
{
if(a==NULL)
return b;
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);
}
}
int main()
{
int t;
cin>>t;
while(t>0)
{
node *head1=NULL;
node *head2=NULL;
int n1,n2;
cin>>n1;
node *a=Create(head1,n1);
cin>>n2;
node *b=Create(head2,n2);
node *c=merge(a,b);
Display(c);
t--;
}
}