Skip to content

Commit b0ccec9

Browse files
Update bubble sort (TheAlgorithms#2806)
1 parent 9567a78 commit b0ccec9

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sorts/BubbleSort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class BubbleSort implements SortAlgorithm {
1818
*/
1919
@Override
2020
public <T extends Comparable<T>> T[] sort(T[] array) {
21-
for (int i = 0, size = array.length; i < size - 1; ++i) {
21+
for (int i = 1, size = array.length; i < size; ++i) {
2222
boolean swapped = false;
23-
for (int j = 0; j < size - 1 - i; ++j) {
23+
for (int j = 0; j < size - i; ++j) {
2424
if (greater(array[j], array[j + 1])) {
2525
swap(array, j, j + 1);
2626
swapped = true;

0 commit comments

Comments
 (0)