update isSorted after shuffling

A list can be sorted after shuffling. The trivial cases are
the empty list and a list with only one element or lists 
with only identical elements. Lists with only a few elements 
have a non-negligible chance to be sorted after shuffling.
This commit is contained in:
2017-12-18 20:10:27 +01:00
parent 297ab6fd40
commit 45dd73d8f3
2 changed files with 50 additions and 1 deletions

View File

@@ -556,7 +556,12 @@ public final class IntList implements Serializable, Cloneable {
data[other] = data[i];
data[i] = tmp;
}
sorted = false;
// update sorted
sorted = true;
for (int i = 1; i < size && sorted; i++) {
sorted = data[i - 1] <= data[i];
}
}
private void ensureCapacity(final int newElements) {