forked from fineanmol/Hacktoberfest2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Union of two array Program from C++ language
- Loading branch information
1 parent
ec55a10
commit 2a8a72c
Showing
2 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
.DS_Store | ||
*.idea* | ||
.github | ||
*.github/ | ||
*.github/ | ||
/.vs |
26 changes: 26 additions & 0 deletions
26
Program's_Contributed_By_Contributors/C++ Programs/Array/Union_of_two_array.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
void getUnion(int a[], int n, int b[], int m) | ||
{ | ||
set<int> s; | ||
for (int i = 0; i < n; i++) | ||
s.insert(a[i]); | ||
|
||
for (int i = 0; i < m; i++) | ||
s.insert(b[i]); | ||
cout << "Number of elements after union operation: " << s.size() << endl; | ||
cout << "The union set of both arrays is :" << endl; | ||
for (auto itr = s.begin(); itr != s.end(); itr++) | ||
cout << *itr | ||
<< " "; | ||
} | ||
|
||
int main() | ||
{ | ||
int a[9] = { 1, 2, 5, 6, 2, 3, 5, 7, 3 }; | ||
int b[10] = { 2, 4, 5, 6, 8, 9, 4, 6, 5, 4 }; | ||
|
||
getUnion(a, 9, b, 10); | ||
} |