-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintersection_sets.cpp
More file actions
43 lines (33 loc) · 847 Bytes
/
intersection_sets.cpp
File metadata and controls
43 lines (33 loc) · 847 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
43
//take intersection of 2 sets of strings
#include "intersection_sets.h"
#include <iostream>
#include <set>
intersection_sets::intersection_sets()
{
}
std::set<std::string> intersection_sets::set_intersection(std::set<std::string> set1, std::set<std::string> set2) {
std::set<std::string> result;
for (std::string x : set1) {
if (set2.count(x)) {
result.insert(x);
}
}
return result;
}
/*main to test
#include <iostream>
#include <set>
#include "intersection_sets.h"
using namespace std;
int main() {
set<string> set1 = {"je","h", "j"};
set<string> set2 = {"h", "k", "je"};
Intersection_sets test;
set<string> intersection_set;
intersection_set = test.set_intersection(set1, set2);
for (string x : intersection_set) {
cout << x << " ";
}
return 0;
}
*/