Merge pull request #866 from shellhub/master

make code more readable
This commit is contained in:
Yang Libin 2019-09-26 10:29:56 +08:00 committed by GitHub
commit f0bdd2b646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,18 +18,15 @@ class BubbleSort implements SortAlgorithm {
@Override
public <T extends Comparable<T>> T[] sort(T array[]) {
int last = array.length;
//Sorting
boolean swap;
do {
swap = false;
for (int count = 0; count < last - 1; count++) {
if (less(array[count], array[count + 1])) {
swap = swap(array, count, count + 1);
}
for (int i = 0, size = array.length; i < size - 1; ++i) {
boolean swapped = false;
for (int j = 0; j < size - 1 - i; ++j) {
swapped = less(array[j], array[j + 1]) && swap(array, j, j + 1);
}
last--;
} while (swap);
if (!swapped) {
break;
}
}
return array;
}