Merge pull request #1174 from cganey/BubbleSortLogic
Update BubbleSort.java
This commit is contained in:
commit
d9c7b8477e
@ -21,7 +21,10 @@ class BubbleSort implements SortAlgorithm {
|
|||||||
for (int i = 0, size = array.length; i < size - 1; ++i) {
|
for (int i = 0, size = array.length; i < size - 1; ++i) {
|
||||||
boolean swapped = false;
|
boolean swapped = false;
|
||||||
for (int j = 0; j < size - 1 - i; ++j) {
|
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) {
|
if (!swapped) {
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user