-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbucketsort_test.cpp
More file actions
executable file
·78 lines (56 loc) · 1.45 KB
/
Copy pathbucketsort_test.cpp
File metadata and controls
executable file
·78 lines (56 loc) · 1.45 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
/*
* bucketsort_test.cpp
*
* Created on: 2013-11-21
* Author: Rong Xiao
*/
/*
* heapsort_test.cpp
*
* Created on: 2013-11-21
* Author: Rong Xiao
*/
#include "bucketsort.hpp"
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
size_t id(const int& x) {
return static_cast<size_t>(x);
}
int main(int argc, char** argv) {
size_t m = 0;
vector<int> *M = NULL;
if (argc>2) {
m = argc - 1;
M = new vector<int>(m);
for (size_t i = 1; i < argc; ++i) {
(*M)[i-1] = atoi(argv[i]);
// cout << ' ' << (*M)[i-1];
}
cout << endl;
} else {
m = static_cast<size_t>(atoi(argv[1]));
M = new vector<int>(m);
srand (time(NULL));
for (size_t i = 0; i < m; ++i) {
(*M)[i] = rand() % 100;
// cout << ' ' << (*M)[i];
}
cout << endl;
}
sortutils::KeyOrder<int> keyorder(id, 100);
clock_t begin = clock();
sortutils::bucketsort<vector<int>::iterator, int, sortutils::KeyOrder<int> >(M->begin(), M->begin()+m, keyorder);
cout << "Sort timing: "<< double(clock() - begin) / CLOCKS_PER_SEC << endl;
/*
cout << "After sort: " << endl;
for (size_t i = 0; i < m; ++i) {
cout << ' ' << (*M)[i];
}
cout << endl;
*/
delete M;
return 0;
}