Java实现插入排序
public class InsertSort {
public static void insertSort(int [] list){
for(int i=2;i<list.length;i++){
list[0] = list[i];
int currentElement = list[i];
int k;
for(k=i-1;list[k]>currentElement;k--){
list[k+1] = list[k];
}
list[k+1] = currentElement;
}
}
public static void main(String[] args) {
int [] list = {0,2,3,2,5,6,1,-2,3,14,12};
insertSort(list);
for(int i=0;i<list.length;i++){
System.out.print(list[i]+" ");
}
}
}