-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.cpp
More file actions
87 lines (63 loc) · 1.87 KB
/
run.cpp
File metadata and controls
87 lines (63 loc) · 1.87 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
79
80
81
82
83
84
85
86
87
#define VECTOR_TEST
#include <iostream>
#include <string>
#include <vector>
#include "vector_utility.cpp"
#include "quicksort.cpp"
#include "mergesort.cpp"
#include "heapsort.cpp"
#include "bubblesort.cpp"
#include "selectionsort.cpp"
#include "insertionsort.cpp"
// testing
#include "introsort.cpp"
using namespace std;
typedef int data_type;
int main() {
//// List of algorithms
vector<void (*)(data_type*,int)> sortingFuncs;
vector<string> f_names;
sortingFuncs.push_back(quicksort);
f_names.push_back("quicksort");
sortingFuncs.push_back(quicksortRandomPivot);
f_names.push_back("quicksortRandomPivot");
f_names.push_back("mergesort");
sortingFuncs.push_back(mergesort);
f_names.push_back("mergesortInPlace");
sortingFuncs.push_back(mergesortInPlace);
f_names.push_back("heapsort");
sortingFuncs.push_back(heapsort);
sortingFuncs.push_back(bubblesort);
f_names.push_back("bubblesort");
sortingFuncs.push_back(selectionsort);
f_names.push_back("selectionsort");
sortingFuncs.push_back(insertionsort);
f_names.push_back("insertionsort");
sortingFuncs.push_back(introsort);
f_names.push_back("introsort");
// input and output data files
string input, output;
cout << "This programs will assume integer arrays." << endl;
cout << "Input file: ";
cin >> input;
cout << "Output file: ";
cin >> output;
int option;
cout << "Algorithm list:" << endl;
for (int i=0; i<f_names.size(); i++) {
cout << i << ":\t" << f_names[i] << endl;
}
cout << "Select Algorithm: ";
cin >> option;
if (option<0 || option>=f_names.size()) {
cout << "Option out of bound." << endl;
return -1;
}
int size;
data_type *v;
v = readVectorFromFile<data_type>(&size, input);
double t = measureTimeOf(sortingFuncs[option], v, size);
cout << f_names[option] << " in " << t << "sec for " << size << " elements." << endl;
writeFileWithVector(v, size, output, "");
return 0;
}