forked from piyush-kash/Hacktober2021-cpp-py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunion_elements.cpp
More file actions
42 lines (38 loc) · 779 Bytes
/
Copy pathunion_elements.cpp
File metadata and controls
42 lines (38 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// union elements to print between 2 arrays
#include<bits/stdc++.h>
using namespace std;
void uni(int a[],int b[],int m,int n) // int uni(int a[],int b[],int m,int n) --to return size
{
unordered_set<int> s;
for(int i=0;i<m;i++)
{
s.insert(a[i]); // s.add(a[i]);
}
for(int i=0;i<n;i++)
{
s.insert(b[i]); // s.add(b[i]);
}
for(auto it=s.begin();it!=s.end();it++) // return s.size();
{
cout<<*it<<" ";
}
}
int main()
{
int m;
cin>>m;
int a[m];
for(int i=0;i<m;i++)
{
cin>>a[i];
}
int n;
cin>>n;
int b[n];
for(int i=0;i<n;i++)
{
cin>>b[i];
}
uni(a,b,m,n);
return 0;
}