-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
76 lines (65 loc) · 1.61 KB
/
main.cpp
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
/*
* main.cpp
* Name: Harry Kran-Annexstein
*
* This program sorts numbers provided in a text file, and prints out the sorted
* number to stdout (the screen).
* It accepts 2 command-line parameters, the first an integer representing
* the sort to use. 0 Selection sort, 1 Coctail sort, 2 Gnomesort, 3 Shellsort,
* 4 Your Best Sort.
* The second paremeter is a filename of a file containing the numbers to sort.
* The file has one integer (could have many digits) per line.
*
* Nov 6, 2013
*/
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include "Sort.h"
using namespace std;
int main(int argc, char* argv[]){
if (argc != 3) {
cout << "Program requires 2 input parameters: "<< endl
<< "1. An integer from 0-4 representing sort type, " << endl
<< "2. File containing numbers to sort." << endl;
return 0;
}
int sort = atoi(argv[1]);
ifstream file;
file.open(argv[2]);
if(file.fail()){
cout << "Error opening: " << argv[2] << " Please try again." << endl;
return 0;
}
vector<int> array;
int inum;
while(file >> inum){
array.push_back(inum);
}
file.close();
Sort s;
switch(sort) {
case 0:
array = s.selectionSort(array);
break;
case 1:
array = s.cocktailSort(array);
break;
case 2:
array = s.gnomeSort(array);
break;
case 3:
array = s.shellSort(array);
break;
case 4:
array = s.yourBestSort(array);
break;
default:
cout << "Desired sort must be identified as an integer 0 to 4." << endl;
}
for (unsigned i = 0; i < array.size(); i++) {
cout << array[i] << endl;
}
return 0;
}