1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.*;

class Program {
public static int[] bubbleSort(int[] array) {
int count = 1;
boolean isSorted = false;
while (!isSorted) {
isSorted = true;
for (int i = 0; i < array.length - count; i++) {
if (array[i] > array[i + 1]) {
swap(array, i, i + 1);
isSorted = false;
}
}
count += 1;
}

return array;
}

public static void swap(int[] array, int idx1, int idx2) {
int i = array[idx1];
array[idx1] = array[idx2];
array[idx2] = i;
}
}