-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverifySort.cpp
More file actions
55 lines (48 loc) · 955 Bytes
/
Copy pathverifySort.cpp
File metadata and controls
55 lines (48 loc) · 955 Bytes
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
//I certify that this program is my own original work.
//I did not copy any part of this program from any other source.
//I further certify that I typed each and every line of code in this program.
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
bool isSorted(int arr[],int max)
{
for(int i=0; i < max;i++)
{ if(!(arr[i+1] >= arr[i]))
{
cout << "ARRAY is UNSORTED with arr[i]:"<<arr[i]<<" and arr[i+1]: "<<arr[i+1]<<" on line:"<<i <<endl;
return false;
}
}
return true;
}
int main(int argc,char* argv[])
{
ofstream out;
ifstream in;
const int max=1000000;
int arr[max];
int count=0;
int n;
in.open(argv[1]);
while(!in.eof())
{
in >> n;
arr[count]=n;
count++;
}
count=count-1;
if(is_sorted(arr,arr+1))
{ cout<<"SORTED\n";
}
else
{
cout<<"not\n";
}
if(isSorted(arr,count) == true){
cout << "ARRAY IS SORTED: " << max << endl;
}
out.close();
in.close();
return 0;
}