#include
using namespace std;
class Node{
public:
int data;
Nodenext;
Node(int d)
{
data=d;
next=NULL;
}
};
void insert(Node&head,int data)
{
if(head==NULL)
{
head=new Node(data);
}
Node*temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=new Node(data);
return;
}
void print(Nodehead)
{
while(head!=NULL)
{
cout<data<<" ";
head=head->next;
}
}
void linkedlist(Node&head,int b)
{
int data;
cin>>data;
while(b–)
{
insert(head,data);
cin>>data;
}
return;
}
Nodemerge(Nodehead1,Nodehead2)
{
if(head1==NULL)
{
return head2;
}
else if(head2==NULL)
{
return head1;
}
Nodec;
if(head1->datadata)
{
c=head1;
c->next=merge(head1->next,head2);
}
else{
c=head2;
c->next=merge(head1,head2->next);
}
return c;
}
int main() {
int n,t,k;
Nodehead=NULL;
Nodehead1=NULL,*head2=NULL;
cin>>n;
while(n–){
cin>>t;
linkedlist(head1,t);
cin>>k;
linkedlist(head2,k);
Node*d=merge(head1,head2);
print(d);
}
return 0;
}
output=1 1 3 4 4 5 6 7
why 1 and 4 printing twice?