Update bubble sort (#2806)

This commit is contained in:
Du Yuanchao 2021-11-03 09:07:59 +08:00 committed by GitHub
parent 9567a78521
commit b0ccec9d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,9 +18,9 @@ class BubbleSort implements SortAlgorithm {
*/
@Override
public <T extends Comparable<T>> T[] sort(T[] array) {
for (int i = 0, size = array.length; i < size - 1; ++i) {
for (int i = 1, size = array.length; i < size; ++i) {
boolean swapped = false;
for (int j = 0; j < size - 1 - i; ++j) {
for (int j = 0; j < size - i; ++j) {
if (greater(array[j], array[j + 1])) {
swap(array, j, j + 1);
swapped = true;