---
title: "8种Java排序算法总结2(ZZ)"
author: "apprentice_ll26"
date: "2010-04-15T09:13:46Z"
tags: []
categories: ["编程语言"]
slug: "8-java-2-zz"
draft: false
lastmod: "2010-04-15T09:13:46Z"
id: 644260
url: "https://apprentice-ll26.iteye.com/blog/644260"
---

4、 希尔排序

希尔排序并不稳定，O(1)的额外空间，时间复杂度为O(N*(logN)^2)。这中算法是基于插入排序的。最坏的情况下的执行效率和在平均情况下的执行效率相比相差不多。

  
```java
  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;

       }

   }
```