-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathch4-selection.cpp
43 lines (38 loc) · 1.21 KB
/
ch4-selection.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
#include <iostream>
#include <sstream>
#include "my_intrinsics.h"
#include "my_selection.h"
#include "my_type_functions.h"
using namespace std;
template<typename T1, typename T2>
bool precedes(const pair<T1, T2>& a,
const pair<T1, T2>& b)
{
if (a.first > b.first) return false;
if (a.second > b.second) return false;
if (a.first == b.first && a.second == b.second) return false;
return true;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& output, pair<T1, T2> p)
{
stringstream combiner;
combiner << "(" << p.first << ", " << p.second << ")";
return (output << combiner.str());
}
bool less_than(int a, int b) {
return a < b;
}
int main() {
pair<int, int> a(3, 3);
pair<int, int> b(0, 0);
pair<int, int> c(2, 1);
pair<int, int> d(1, 2);
pair<int, int> e(0, 1);
cout << select_0_4(a, b, c, d, precedes<int, int>) << endl;
cout << select_1_4(a, b, c, d, precedes<int, int>) << endl;
cout << select_2_4(a, b, c, d, precedes<int, int>) << endl;
cout << select_3_4(a, b, c, d, precedes<int, int>) << endl;
cout << median_5(a, b, d, c, e, precedes<int, int>) << endl;
cout << my_median_5(a, b, d, c, e, precedes<int, int>) << endl;
}