-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHW8.cpp
More file actions
146 lines (129 loc) · 4.85 KB
/
Copy pathHW8.cpp
File metadata and controls
146 lines (129 loc) · 4.85 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//HW8. Due: Thursday, April 27 at 11:59pm
//Jillian Handrahan
// jehandra@syr.edu
//8377009572
#include <iostream>
#include <map>
#include <list>
#include <vector>
#include <set>
#include <unordered_set>
using namespace std;
//when comparing equality of two structures, always compare sums of all int values in the structures
//When Hashing a structure, always hash the sum of all int values in the structure
//For printing, map: { ...} vector: [...] set(or unordered set): <...>
class myCompare {
public:
bool operator() (const set<int>* p1, const set<int>* pw) const {
int sum1;
int sum2;
sum1 = 0;
sum2 = 0;
for (auto i: *p1) {
sum1+= i;
}
for (auto i : *pw) {
sum2 += i;
}
cout << "hi" << endl;
return sum1<sum2;
}
bool operator() (const set<set<int>*>* p1, const set<set<int>*>* pw) const {
int sum1= 0;
int sum2 = 0;
for (auto& i : *p1) {
for (auto j : *i) {
sum1+= j;
}
}
for (auto& i : *pw) {
for (auto j : *i) {
sum2+= j;
}
}
cout << "ji " << sum1;
cout << "pee " << sum2;
return sum1 < sum2;
}
bool operator()( const map < set<set<int>*>*, vector<int>* , myCompare> p1, const map < set<set<int>*>*, vector<int>*, myCompare > pw) const {
//For comparisons, compare the sums of all int values in the structures.
int sum1 = 0;
int sum2 = 0;
auto sumPoint{ p1.begin() };
while (sumPoint != p1.end()) {
auto setSetPoint{ sumPoint->first->begin() };
while (setSetPoint != sumPoint->first->end()) {
for (auto setP : **setSetPoint ){
sum1 += setP;
}
setSetPoint++;
}
auto vecPoint{ sumPoint->second->begin() };
while (vecPoint != sumPoint->second->end()) {
sum1 += *vecPoint;
vecPoint++;
}
sumPoint++;
}
sumPoint = pw.begin();
while (sumPoint != pw.end()) {
auto setSetPoint{ sumPoint->first->begin() };
while (setSetPoint != sumPoint->first->end()) {
for (auto setP : **setSetPoint ){
sum2 += setP;
}
setSetPoint++;
}
auto vecPoint{ sumPoint->second->begin() };
while (vecPoint != sumPoint->second->end()) {
sum2 += *vecPoint;
vecPoint++;
}
sumPoint++;
}
// cout << sum1 << endl;
// cout << sum2 << endl;
//return a bool value.
return sum1 < sum2;
}
friend ostream& operator<<(ostream& str, const set<map < set<set<int>*>*, vector<int>* , myCompare>, myCompare>& S) {
str << "{ " << endl;
for (auto i : S) { //for every map in the set
str << "{ ";
for (auto setSet : i) {
for (auto& lst : *setSet.first){
str << "< ";
for (auto val : *lst) {
str << val << " ";
}
str << "> ";
}
str << "[ ";
for (auto vec : *setSet.second){
str << vec << " ";
}
str << "] ";
}
str << "}" << endl;
}
str << "}" << endl;
return str;
}
};
int main() {
//The following statement won't compile. Fix it.
set<map < set<set<int>*>*, vector<int>*, myCompare >, myCompare> S1{ //set
{{new set<set<int>*>{ new set<int>{16,36,56}, new set<int>{ 1, 2, 36}, new set<int>{5,46,36}}, new vector<int>{1, 2, 3} }}, //map 1
{{new set<set<int>*>{ new set<int>{4,2,5}, new set<int>{ 1, 4, 3}, new set<int>{5,12,31}}, new vector<int>{1, 20, 13} }}, //map 2
{{new set<set<int>*>{ new set<int>{4,2,5}, new set<int>{ 1, 41, 3}, new set<int>{5,12,34}}, new vector<int>{1, 20, 13} }} //map 3
};//Create your initial values with at least 3 elements in every STL container.
cout << S1 << endl;
//The following statement won't compile. Fix it.
// unordered_set< map < set<set<int>*>*, vector<int>* >> H1 { //set
// {{new set<set<int>*>{ new set<int>{1,3,5}, new set<int>{ 1, 20, 3}, new set<int>{5,46,3}}, new vector<int>{1, 2, 3} }}, //map 1
// {{new set<set<int>*>{ new set<int>{4,2,5}, new set<int>{ 1, 4, 3}, new set<int>{5,12,31}}, new vector<int>{1, 20, 13} }}, //map 2
// {{new set<set<int>*>{ new set<int>{4,2,5}, new set<int>{ 1, 4, 3}, new set<int>{5,12,31}}, new vector<int>{1, 20, 13} }} //map 3
// };//You can re-use the above.
// cout << H1 << endl;//print bucket arrays
return 0;
}