forked from SilverMaple/STLSourceCodeNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6_5_set-algorithms.cpp
More file actions
56 lines (44 loc) · 1.4 KB
/
6_5_set-algorithms.cpp
File metadata and controls
56 lines (44 loc) · 1.4 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
// file: 6set-algorithms.cpp
#include <set> // multiset
#include <iostream>
#include <algorithm>
#include <iterator> // ostream_iterator
using namespace std;
template <class T>
struct display {
void operator() (const T& x) {
cout << x << ' ';
}
};
int main() {
int ia1[6] = {1, 3, 5, 7, 9, 11};
int ia2[7] = {1, 1, 2, 3, 5, 8, 13};
multiset<int> S1(ia1, ia1 + 6);
multiset<int> S2(ia2, ia2 + 7);
for_each(S1.begin(), S1.end(), display<int>());
cout << endl;
for_each(S2.begin(), S2.end(), display<int>());
cout << endl;
auto first1 = S1.begin();
auto last1 = S1.end();
auto first2 = S2.begin();
auto last2 = S2.end();
cout << "Union of S1 and S2: ";
set_union(first1, last1, first2, last2, ostream_iterator<int>(cout, " "));
cout << endl;
first1 = S1.begin();
first2 = S2.begin();
cout << "Intersection of S1 and S2: ";
set_intersection(first1, last1, first2, last2, ostream_iterator<int>(cout, " "));
cout << endl;
first1 = S1.begin();
first2 = S2.begin();
cout << "Difference of S1 and S2: ";
set_difference(first1, last1, first2, last2, ostream_iterator<int>(cout, " "));
cout << endl;
first1 = S1.begin();
first2 = S2.begin();
cout << "Symmetric difference of S1 and S2: ";
set_symmetric_difference(first1, last1, first2, last2, ostream_iterator<int>(cout, " "));
cout << endl;
}