-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
58 lines (46 loc) · 1.33 KB
/
test.cpp
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
#include<bits/stdc++.h>
using namespace std;
struct edge {
int weight;
int src;
int dest;
bool operator <(const edge& e) const {
if(weight == e.weight) {
if(src == e.src)
return dest < e.dest;
return src < e.src;
}
return weight < e.weight;
}
};
edge* createEdge(int weight, int a, int b) {
edge *newEdge = new edge;
newEdge->weight = weight;
newEdge->src = a;
newEdge->dest = b;
return newEdge;
}
int main (){
set<pair<int, int> > st;
st.insert(make_pair(1,5));
st.insert(make_pair(3,6));
st.insert(make_pair(2,7));
//if pairs are used in set, ordering is based on first property of pair
for(set<pair<int, int> > :: iterator it= st.begin(); it!=st.end(); it++) {
printf("%d : %d\n",it->first, it->second);
}
if(-1)
printf("If condition also passes negative numbers\n");
else
printf("If condition doesn't pass negative numbers\n");
set<struct edge> s;
s.insert({5,1,2});
s.insert({3,2,3});
s.insert({7,6,2});
s.insert({7,4,3});
//if structs are used in set, ordering is based on first property of pair
for(set<struct edge> :: iterator it= s.begin(); it!=s.end(); it++) {
printf("%d : %d %d\n",it->weight, it->src, it->dest);
}
return 0;
}