MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / isSorted

Method isSorted

src/main/java/com/thealgorithms/sorts/SortUtils.java:98–105  ·  view source on GitHub ↗

Checks whether the array is sorted in ascending order. @param array the array to check @return true if the array is sorted in ascending order, false otherwise

(T[] array)

Source from the content-addressed store, hash-verified

96 * @return true if the array is sorted in ascending order, false otherwise
97 */
98 public static <T extends Comparable<T>> boolean isSorted(T[] array) {
99 for (int i = 1; i < array.length; i++) {
100 if (less(array[i], array[i - 1])) {
101 return false;
102 }
103 }
104 return true;
105 }
106
107 /**
108 * Checks whether the list is sorted in ascending order.

Callers 15

testEmptyArrayMethod · 0.95
testSingleValueMethod · 0.95
testIntegerArrayMethod · 0.95
testWithDuplicatesMethod · 0.95
testWithStringArrayMethod · 0.95
testWithRandomArrayMethod · 0.95
isSortedEmptyArrayMethod · 0.95
isSortedArrayTrueMethod · 0.95
isSortedArrayFalseMethod · 0.95
isSortedListTrueMethod · 0.95

Calls 3

lessMethod · 0.95
sizeMethod · 0.65
getMethod · 0.45

Tested by 15

testEmptyArrayMethod · 0.76
testSingleValueMethod · 0.76
testIntegerArrayMethod · 0.76
testWithDuplicatesMethod · 0.76
testWithStringArrayMethod · 0.76
testWithRandomArrayMethod · 0.76
isSortedEmptyArrayMethod · 0.76
isSortedArrayTrueMethod · 0.76
isSortedArrayFalseMethod · 0.76
isSortedListTrueMethod · 0.76