-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15.Union.cpp
More file actions
74 lines (68 loc) · 1.21 KB
/
15.Union.cpp
File metadata and controls
74 lines (68 loc) · 1.21 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
using namespace std;
void arrayUnion(int a[], int b[], int m, int n)
{
int i = 0, j = 0;
while(i < m && j < n)
{
if(i > 0 && a[i] == a[i-1])
{
i++;
continue;
}
if(j > 0 && b[j] == b[j-1])
{
j++;
continue;
}
if(a[i] < b[j])
{
cout << a[i] << " ";
i++;
}
else if(a[i] > b[j])
{
cout << b[j] << " ";
j++;
}
else
{
cout << a[i] << " ";
i++;
j++;
}
}
while(i < m)
{
if(i > 0 && a[i] == a[i-1])
{
i++;
continue;
}
else
{
cout << a[i] << " ";
i++;
}
}
while(j < n)
{
if(j > 0 && b[j] == b[j-1])
{
j++;
continue;
}
else
{
cout << b[j] << " ";
j++;
}
}
}
int main()
{
int a[] = {3,5,8};
int b[] = {2,8,9,10,15};
arrayUnion(a, b, 3, 5);
return 0;
}