package vip.ithyl.insertsort.practice;
/**
* 插入排序
* @author IThyl
*
*/
public class InsertSortNew {
public static void main(String[] args) {
int[] a={2,5,3,9,8,4,10,7};
insertSort(a);
}
static void insertSort(int[] a){
for(int i=1 ;i<a.length;i++){
int key = a[i];
int j=i-1;
while(j>=0&&a[j]<key){
a[j+1]=a[j];
j--;
}
a[j+1]=key;
}
for(int e:a){
System.out.print(e+">=");
}
}
}
结果:
10>=9>=8>=7>=5>=4>=3>=2>=
算法——插入排序
最新推荐文章于 2024-09-13 13:21:04 发布