(3)用 java 实现
package com.njue;
public class insertSort {
public insertSort(){
inta[]={49,38,65,97,76,13,27,49,78,34,12,64,5,4,62,99,98,54,56,17
,18,23,34,15,35,25,53,51};
int temp=0;
for(int i=1;i<a.length;i++){
int j=i-1;
temp=a[i];
for(;j>=0&&temp<a[j];j--){
a[j+1]=a[j]; //将大于 temp 的值整体后移一个单位
}
a[j+1]=temp;
}
for(int i=0;i<a.length;i++)
System.out.println(a[i]);
}
}
2,希尔排序(最小增量排序)
(1)基本思想:算法先将要排序的一组数按某个增量 d(n/2,n 为要排序数的
个数)分成若干组,每组中记录的下标相差 d.对每组中全部元素进行直接插入