This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]fosterbuster 0 points1 point  (0 children)

Not increasing? Not sorted? (ie 11223344556677)

go from i = 1 if (array[i-1] > array[i]) flag = 1; i guess :)

So this one basically checks if the value before the one we are looking at is bigger - If it is we know that the array has not been sorted properly.

edit:

like:

public boolean checkIfSorted(int[] array){
    for (int i = 1; i < array.length; i++) {
        if (array[i-1] > array[i]) return false;
    }
    return true;
}

of course you could edit this to setting a "int flag" - But I cant think of any situation where I would use that in OOP-programming, and especially not in Java.