public class Bubble {
public static void sort(Comparable[] a) {
for (int i = 0; i < a.length - 1; i++) {
for (int j = 0; j < a.length - 1-i; j++) {
if (compare(a[j], a[j + 1])) {
exchange(a,j, j + 1);
}
}
}
}
public static void exchange(Comparable[] a,int k,int b){
Comparable temp;
temp = a[k];
a[k] = a[b];
a[b] = temp;
}
public static boolean compare(Comparable x,Comparable y){
return x.compareTo(y) > 0;
}
}
import java.util.Arrays;
public class BubbleTest {
public static void main(String[] args) {
Integer[] a = {12,4,6,5,1,3,2,9,8,4,1};
Bubble.sort(a);
System.out.println(Arrays.toString(a));
}
}