title: 希尔排序实现代码
date: 2019-06-11 21:40:13
tags:
简单的希尔排序代码:
更加优秀的增量序列是9*4^i-9*2^i+1
和4^i-3*2^i+1
形式排序出的数组序列
public class ShellSort2 <AnyType extends Comparable<? super AnyType>>{
public static <AnyType extends Comparable<? super AnyType>>AnyType[] sort(AnyType[] a) {
int x;
for(int i = (a.length/2);i>0;i /= 2) {
for(int j = i;j<a.length;j++) {
AnyType tmp = a[j];
for(x = j;x>=i&&(tmp.compareTo(a[x-i])<0);x-=i) {
a[x] = a[x-i];
}
a[x] = tmp;
}
}
return a;
}