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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user