so how to make such logic
int[] arr = {2, 5, 3};
if (/* arr is sorted */)
....
else
...
Its bad that method Array.sort is void
Well you can check it in O(n) worst case linear time. A non-sorted array (assuming you mean sorting in ascending order) will have a trip point. That is at some point arr[i] > arr[i+1]
All you need to do is
boolean is_array_sorted(int arr[]) {
for(int i=0; i < arr.len-1; i++) {
if(arr[i] > arr[i+1]) {
return false;
}
}
return true;
}
Just change the > to < if your array sort is supposed to be descending order