package zwz;
public class Zwz {
public static void main(String[] args) {
int[] a={10,5,2,4,7};
System.out.println(a[0]+" "+a[1]+" "+a[2]+" "+a[3]+" "+a[4]);
int i,j,key;
//用for语句实现插入排序。。大的数据依次往后移动
for(j=0;j<5;j++){
key=a[j];
i=j-1;
while(i>=0&&a[i]>key){
a[i+1]=a[i];
i--;
}
a[i+1]=key;
}
//打印出排序后的顺序
for(int k=0;k<5;k++){
System.out.print(a[k]+" ");
}
}
}
运行结果: