public static void main(String[] args) {
int [] arry= {1,2,3,4,5,0,6};
for(int i=1;i<arry.length;i++) {
if (arry[i]<arry[i-1]) {
int temp=arry[i];//保存该下标的数值
for(int j=i-1;j>=0;j--) {
if(temp<arry[j]) {
arry[j+1]=arry[j];//循环右移
}else {
arry[j+1]=temp;
break;
}
//最大最小值在数组首尾的时候
if(j==0) {
arry[0]=temp;
}
}
}
}
for(int v:arry) {
System.out.println(" "+v);
}
}
}
JAVA插入排序
最新推荐文章于 2020-12-15 11:01:05 发布