/**
* Created by Administrator on 2017/4/8.
*基于插入排序,但是比插入排序简单,比插入排序快
* 希尔排序,从小到大
*/
public class ShellSort {
public void shell(int[] ss){
for(int k=ss.length/2;k>0;k=k/2){
for(int i=k;i
for(int j=k;j
if(ss[j-k]>ss[j]){
int temp=ss[j];
ss[j]=ss[j-k];
ss[j-k]=temp;
}
}
}
}
}
public static void main(String[] args) {
int[] ss={3,5,23,34,98,89,65,90};
ShellSort scort=new ShellSort();
scort.shell(ss);
for(int i=0;i
System.out.print(ss[i]+" ");
}
}
复杂度一般为O(n^1.3),而插入排序为:O(n^2),希尔方法简单,快一些