-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverifySort.cpp
More file actions
52 lines (43 loc) · 1 KB
/
verifySort.cpp
File metadata and controls
52 lines (43 loc) · 1 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
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
if (argc < 3)
{
cout << "Please include input filename and output filename in param list.\n";
cout << "Example:\n";
cout << " % mySortA numbers.txt mySorted.txt\n";
exit(EXIT_SUCCESS);
}
const int MAX = 1000000;
ofstream fout;
ifstream fin;
int n;
int v[MAX];
int count = 0;
fin.open(argv[1]);
while (fin >> n )
{
v[count++] = n; // insert a number into the arary and increase the index
}
int checker = 0;
for(int i=0; i < (sizeof(v)/sizeof(v[0]))-1; i++){
if(v[i] > v[i+1]){
cout << (sizeof(v)/sizeof(v[0])) << " Not Sorted" << endl;
cout <<"Line error: " << i << endl;
checker = 1;
break;
}
}
if(checker == 0){
cout << (sizeof(v)/sizeof(v[0])) << " Sorted" << endl;
}
//fout.open(argv[2], ios::out | ios::trunc);
//for (int i = 0; i < count; i++)
// fout << v[i]<<endl;
//fout.close();
fin.close();
return 0;
}