-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsort1.cpp
More file actions
53 lines (44 loc) · 1021 Bytes
/
sort1.cpp
File metadata and controls
53 lines (44 loc) · 1021 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
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <set>
#include <algorithm>
#include <sequtils.h>
using namespace std;
template<typename T>
class RuntimeCmp {
public :
enum cmp_mode { normal, reverse };
private :
cmp_mode mode;
public :
RuntimeCmp(cmp_mode m = normal): mode(m) {}
bool operator()(const T &t1, const T &t2) const {
return mode == normal ? t1 < t2 : t2 < t1;
}
bool operator == (const RuntimeCmp& rc) {
return mode == rc.mode;
}
};
typedef set<int, RuntimeCmp<int> > IntSet;
int main(int argc, char *argv[])
{
IntSet s;
random_init();
populate_rand(s, 10, 20);
print_seq(s);
RuntimeCmp<int> reverse_order(RuntimeCmp<int>::reverse);
IntSet s2(reverse_order);
populate_rand(s2, 10, 20);
print_seq(s2);
s = s2;
s.insert(3);
print_seq(s, "s :");
print_seq(s2, "s2 :");
if (s.value_comp() == s2.value_comp()) {
cout << "s and s2 have same coparation criteria"
<< endl;
} else {
cout << "s and s2 have different comparation criteria"
<< endl;
}
return 0;
}