make code more readable

This commit is contained in:
shellhub
2019-09-26 10:02:58 +08:00
parent ee0a48fa14
commit 8881e9aa4e

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;
}