-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheapsort_test.cpp
More file actions
executable file
·64 lines (45 loc) · 1.15 KB
/
Copy pathheapsort_test.cpp
File metadata and controls
executable file
·64 lines (45 loc) · 1.15 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
/*
* heapsort_test.cpp
*
* Created on: 2013-11-21
* Author: Rong Xiao
*/
#include "heapsort.hpp"
#include <iostream>
#include <vector>
#include <ctime>
using namespace std;
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;
}
clock_t begin = clock();
sortutils::heapsort(M->begin(), M->begin()+m);
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;
}