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