shell排序 类似于插入排序

来源:互联网 发布:php幸运大转盘源码 编辑:程序博客网 时间:2024/04/28 22:41

1,  shell排序 类似于插入排序。

h = 3*h+1

 

间隔序列中的数字互质。

 

    public void shellSort(){

       int inner,outer;

       long temp;

       int h = 1;

      

       while(h <= nElems/3){

           h = h*3 + 1;

       }

       System.out.println("1  h= "+h);

       while(h>0){

           for(outer = h;outer<nElems;outer++){

              temp = a[outer];

              inner = outer;

              while(inner > h-1 && a[inner-h] >= temp){

                  a[inner] = a[inner-h];

                  inner -= h;

              }

              a[inner] = temp;

           }

           h = (h-1)/3;

       }

      

      

    }

 

 

Shell 效率:O{N^(3/2)} -O{N^(7/6)}

   


原创粉丝点击