Skip to content

Commit d9c7b84

Browse files
authored
Merge pull request TheAlgorithms#1174 from cganey/BubbleSortLogic
Update BubbleSort.java
2 parents b14cb96 + 3259944 commit d9c7b84

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sorts/BubbleSort.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public <T extends Comparable<T>> T[] sort(T array[]) {
2121
for (int i = 0, size = array.length; i < size - 1; ++i) {
2222
boolean swapped = false;
2323
for (int j = 0; j < size - 1 - i; ++j) {
24-
swapped = less(array[j], array[j + 1]) && swap(array, j, j + 1);
24+
if (less(array[j], array[j + 1])) {
25+
swap(array, j, j + 1);
26+
swapped = true;
27+
}
2528
}
2629
if (!swapped) {
2730
break;

0 commit comments

Comments
 (0)