1.希尔排序的基本思想
先将整个待排记录序列分割成为若干个子序列分别进行直接插入,待整个序列中的记录基本有序时,再对全体记录进行一次直接插入排序
2.算法实现
Class XiErSort() {
public static void insertionSort(int[] a) {
int j;
for(int gap=a.length/2;gap>0;gap /= 2) {
for(int i=gap;i<a.length;i++) {
int tmp = a[i];
for(j=i;j>=gap&&tmp<a[j-gap];j -= gap) {
a[j] = a[j - gap];
}
a[j] = tmp;
}
}
}
}
3.使用增量的希尔排序的最坏运行时间为O(N ^ (3/2))