Skip to content

Instantly share code, notes, and snippets.

@jongha
Last active August 29, 2015 14:22
Show Gist options
  • Save jongha/9cfe246ae74f1741ba58 to your computer and use it in GitHub Desktop.
Save jongha/9cfe246ae74f1741ba58 to your computer and use it in GitHub Desktop.
#java #sort #algorithm
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