Professional Documents
Culture Documents
#include<iostream>
class node
public:
int data;
node *next;
};
int main()
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
node *first;
node *last;
node *temp;
first=new node();
first->data=a[0];
first->next=NULL;
last=first;
for(int i=1;i<n;i++)
{
temp=new node();
temp->data=a[i];
temp->next=NULL;
last->next=temp;
last=temp;
display(first);
int m;
cin>>m;
int b[m];
for(int i=0;i<m;i++)
cin>>b[i];
node *second;
second=new node();
second->data=b[0];
second->next=NULL;
last=second;
for(int i=1;i<m;i++)
temp=new node();
temp->data=b[i];
temp->next=NULL;
last->next=temp;
last=temp;
node *third;
if(first->data<second->data)
third=last=first;
first=first->next;
last->next=NULL;
else
third=last=second;
second=second->next;
last->next=NULL;
if(first->data<second->data)
last->next=first;
last=first;
first=first->next;
last->next=NULL;
else
last->next=second;
last=second;
second=second->next;
last->next=NULL;
}
if(first)
last->next=first;
else
last->next=second;
display(third);
while(n)
cout<<n->data<<" ";
n=n->next;
cout<<endl;