- 在希尔排序建议的增量序列情况下(h=N/2 Hk):最好时间复杂度和平均时间复杂度都是,最坏时间复杂度为
希尔排序的运行时间依赖于增量序列的选择
/**
* Created by long.chen on 2017/12/28.
*/
public class ShellSort<T extends Comparable<T>> {
public void sheelSort(T[] data) {
int j;
for (int jump = data.length / 2; jump > 0; jump /= 2) {
for (int i = jump; i < data.length; i++) {
T temp = data[i];
for (j = i; j >= jump && temp.compareTo(data[j - jump]) < 0; j -= jump) {
data[j] = data[j - jump];
}
data[j] =temp;
}
}
}
public static void main(String[] args) {
Integer array[] = {40,2,98,72,5,0,16};
ShellSort<Integer> shellSort = new ShellSort<>();
shellSort.sheelSort(array);
for (int i = 0;i<array.length;i++){
System.out.println(array[i]);
}
}
}