Repository navigation
Expand file tree
/
Copy pathsort.cpp
More file actions
64 lines (57 loc) · 1.64 KB
/
Copy pathsort.cpp
File metadata and controls
64 lines (57 loc) · 1.64 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
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include "auxiliary_functions.cpp"
#include "timer.cpp"
using namespace std;
/* Use this file to sort the automatically generated input
*
* NOTE: This is not the implementation of the project code
* This file merely sorts the input so that we can be sure that
* the code we write for our project is sorting correctly.
*
* To invoke this file, use:
* ./sort <input-file> <output-file>
*
* input-file is the file that needs to the sorted
* output-file is the file that contains the sorted numbers from input-file
*/
int main(int argc, char* argv[]){
if(!correctArgumentFormat(argc, argv)){
exit(1);
}
string input_file = argv[1];
vector<int> numbers, holder;
int success = readInputFile(input_file, holder);
//failed reading input file for whatever reason
if(success != 0){cout<<"Error reading input file. Exiting."<<endl; exit(1);}
/*
* Begin timing sequence of:
* Mergesort
*/
int numRuns = 5;
struct timeval start[numRuns];
struct timeval end[numRuns];
vector<float> time;
for(int i = 0; i < numRuns; i++)
{
numbers.clear();
numbers.assign(holder.begin(), holder.end());
start[i] = startTime(&start[i]);
sort(numbers.begin(), numbers.end());
end[i] = endTime(&end[i]);
time.push_back(calculateTime(&start[i], &end[i]));
}
calcAvgTime(time);
/*
* End timing sequence of:
* Mergesort
*/
string output_file = argv[2];
success = outputToFile(output_file, numbers);
if(success != 0){cout<<"Error outputting to file. Exiting."<<endl; exit(1);}
return 0;
}