关于希尔排序
public void shellInertionSort(double [] sorted, int inc){ int sortedLen= sorted.length; for(int j=inc+1;j<sortedLen;j++ ){ if(sorted[j]<sorted[j-inc]){ sorted[0]= sorted[j];// ①先保存一下后面的那个 int insertPos=j; for(int k=j-inc;k>=0;k-=inc){ if(sorted[k]>sorted[0]){ sorted[k+inc]=sorted[k]; //数据结构课本上这个地方没有给出判读,出错: if(k-inc<=0){ insertPos = k; } }else{ insertPos=k+inc; break; } } sorted[insertPos]=sorted[0]; } } } public void shellInsertionSort(double [] sorted){ int[] incs={7,5,3,1}; int num= incs.length; int inc=0; for(int j=0;j<num;j++){ inc= incs[j]; shellInertionSort(sorted,inc); } } void shillsort(int n) { int i,j; int t=1; while (t<n/4) t=t*2+1;//设置增量 while (t>0) { for (i=t;i<n;i++)//对每一块排序 { j=i; int d=a[i]; while(j>=t&&a[j-t]>d) { a[j]=a[j-t]; j-=t; } a[j]=d; } t/=2;//增量变小(即合并过程) } }