-
Notifications
You must be signed in to change notification settings - Fork 0
/
isSorted.cpp
55 lines (49 loc) · 927 Bytes
/
isSorted.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
/*
Is Sorted
*/
#include <iostream>
#include <stdlib.h>
#include <list>
#include <vector>
#include <fstream>
using namespace std;
vector<int> array;
bool isSorted()
{
int prev = array.at(0);
for(int i = 1; i < (int)array.size(); i++) {
if (prev > array.at(i)) {
return false;
}
prev = array.at(i);
}
return true;
}
int main(int argc, char *argv[])
{
//system("uname -a");
if(argc < 3) {
cerr << "Wrong parameters!" << endl;
return -1;
}
int BLOCK_SIZE = 0;
FILE* inputFile;
for(int i = 1; i < argc; i++) {
inputFile = fopen(argv[i], "rb");
fread(&BLOCK_SIZE, sizeof(int), 1, inputFile);
for(int j = 0; j < BLOCK_SIZE; j++) {
int element = 0;
fread(&element, sizeof(int), 1, inputFile);
array.push_back(element);
}
fclose(inputFile);
}
ofstream out("answer");
if (isSorted()) {
out << "is sorted = true";
} else {
out << "is sorted = false";
}
out.close();
return 0;
}