-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection_gen_norec.cpp
More file actions
executable file
·77 lines (64 loc) · 1.56 KB
/
Copy pathselection_gen_norec.cpp
File metadata and controls
executable file
·77 lines (64 loc) · 1.56 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
#include "selection.hpp"
#include <iostream>
#include <vector>
using namespace std;
using namespace selection;
int main(int argc, char** argv) {
size_t m = 0;
int *M = NULL;
if (argc>2) {
m = argc - 1;
M = new int[m];
for (size_t i = 1; i < argc; ++i) {
M[i-1] = atoi(argv[i]);
}
} else {
m = static_cast<size_t>(atoi(argv[1]));
M = new int[m];
srand (time(NULL));
for (size_t i = 0; i < m; ++i) {
M[i] = rand() % 100;
// cout << ' ' << M[i];
}
cout << endl;
}
int mm = median_medians<int*, int>(M, m);
cout << "First medians of medians: " << mm << endl;
/*
for (size_t i = 0; i < m; ++i) {
cout << ' ' << M[i];
}
cout << endl;
*/
size_t p = pivot<int*, int>(mm, M, m);
cout << "Pivoting with mm return: " << p << endl;
/*
for (size_t i = 0; i < m; ++i) {
cout << ' ' << M[i];
}
cout << endl;
*/
cout << "Median: " << select<int*, int>(M, m, m/2) << endl;
/*
for (size_t i = 0; i < m; ++i) {
cout << ' ' << M[i];
}
cout << endl;
*/
vector<int> vec(m);
for (size_t i = 0; i < m; ++i) {
vec[i] = M[i];
// cout << ' ' << vec[i];
}
cout << endl;
cout << "Median: " << select<int*, int>(M, m, m/2) << endl;
cout << "Median of vec: " << select(vec.begin(), m, m/2) << endl;
/*
for (size_t i = 0; i < m; ++i) {
cout << ' ' << vec[i];
}
cout << endl;
*/
delete [] M;
return 0;
}