-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3_3_is_sorted_function.cpp
More file actions
61 lines (47 loc) · 929 Bytes
/
3_3_is_sorted_function.cpp
File metadata and controls
61 lines (47 loc) · 929 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
56
57
58
59
60
61
#include <iostream>
#define D_ARRAY_SIZE 10
using namespace std;
bool isArraySorted(int arr[], int arrSize);
int main()
{
int arr1[D_ARRAY_SIZE] = {1,6,3,1,2,4,9,6,4,2};
bool isSorted = isArraySorted(arr1, D_ARRAY_SIZE);
if (isSorted)
{
printf("Array is sorted\n");
}
else
{
printf("Array is not sorted\n");
}
int arr2[D_ARRAY_SIZE] = {1,1,2,2,4,5,6,7,9,9};
isSorted = isArraySorted(arr2, D_ARRAY_SIZE);
if (isSorted)
{
printf("Array is sorted\n");
}
else
{
printf("Array is not sorted\n");
}
cin.get();
return 0;
}
bool isArraySorted(int arr[], int arrSize)
{
if (arrSize <= 1)
{
return true;
}
int i = 0;
arrSize--;
while(i < arrSize)
{
if(arr[i] > arr[i+1])
{
return false;
}
i++;
}
return true;
}