Update BubbleSort.java

Output from print(integers) returns [78, 231, 54, 23, 12, 9, 6, 4, 1]
Correct output should be: [231, 78, 54, 23, 12, 9, 6, 4, 1]
This commit is contained in:
Chase Ganey
2019-11-23 12:22:27 -05:00
committed by GitHub
parent e08408ca11
commit 3259944dbc

View File

@ -21,7 +21,10 @@ class BubbleSort implements SortAlgorithm {
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);
if (less(array[j], array[j + 1])) {
swap(array, j, j + 1);
swapped = true;
}
}
if (!swapped) {
break;