Union
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y,i,j;
cout<<"Enter the size of first array :";
cin>>x;
cout<<"Enter the size of second array :";
cin>>y;
int a[x], b[y];
cout<<"Enter the elements of first array :";
for(i=0;i<x;i++)
cin>>a[i];
cout<<"Enter the elements of second array :";
for(i=0;i<y;i++)
cin>>b[i];
sort(a,a+x,greater<int>());
sort(b,b+y,greater<int>());
i=0;j=0;
while(i<x && j<y)
{
if(a[i]>b[j])
cout<<a[i++]<<" ";
else if(a[i]<b[j])
cout<<b[j++]<<" ";
else if(a[i]==b[j])
{cout<<a[i++]<<" ";
j++;}
}
while(i<x)
cout<<a[i++]<<" ";
while(j<y)
cout<<b[j++]<<" ";
}
Comments
Post a Comment