`
apprentice_ll26
  • 浏览: 25809 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

8种Java排序算法总结2(ZZ)

阅读更多
4、 希尔排序

希尔排序并不稳定,O(1)的额外空间,时间复杂度为O(N*(logN)^2)。这中算法是基于插入排序的。最坏的情况下的执行效率和在平均情况下的执行效率相比相差不多。

 
  public void shellSort(){

       int inner, outer;

       long temp;

       

       int h=1;

       while(h<nElems/3){

           h=h*3+1;

       }//Knuth序列初始化

       while(h>0){

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

              temp = theArray[outer];

              inner = outer;

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

                  theArray[inner]=theArray[inner];

                  inner-=h;

              }

              theArray[inner]=temp;

           }

           h=(h-1)/3;

       }

   }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics