希尔排序java代码
//希尔排序 通过测试 public class ShellSortTest{ public static void shellSort(int [] arrays){ for(int d=5;d>0;d=d-2){ for(int c=0;c<arrays.length-d;c++){ for(int i=c;i<arrays.length;i=i+d){ for(int j=i;j>0;j=j-d){ if(j<d) break; if(arrays[j]<arrays[j-d]){ int tmp; tmp=arrays[j]; arrays[j]=arrays[j-d]; arrays[j-d]=tmp; } } } } } } //----------------------------------------------------------------------------- public static void main(String[] args){ int x[]={9,8,7,6,5,4,3,2,1}; shellSort(x); for(int i=0;i<=x.length-1;i++){ System.out.println(x[i]); } } }