Update bubble sort (#2806)
This commit is contained in:
parent
9567a78521
commit
b0ccec9d61
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user