Last active
August 29, 2015 14:22
-
-
Save jongha/9cfe246ae74f1741ba58 to your computer and use it in GitHub Desktop.
#java #sort #algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IsSorted { | |
public static void main(String[] args) { | |
System.out.println(isSorted(new int[] { 1, 2, 3, 4 })); // true | |
System.out.println(isSorted(new int[] { 1, 2, 3, 0 })); // false | |
} | |
public static boolean isSorted(int[] items) { | |
for (int i = 0; i < items.length - 1; ++i) { | |
if (items[i] > items[i + 1]) { | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment