//希尔排序 class ShellSort{ public void sort(int[] a){ int d,i,j,temp; for ( d = a.length/2; d >= 1; d=d/2) { for ( i = d; i <a.length ; i=i+d) { if (a[i]<a[i-d]){ temp = a[i]; for ( j = i-d; j>=0 && a[j] >temp ; j= j-d) { a[j+d] = a[j]; } a[j+d] = temp; } } } } }
//哨兵版 class ShellSort{ public void sort(int[] a){ int d,i,j; for ( d = (a.length-1)/2; d >= 1; d=d/2) { for ( i = d+1; i <=a.length-1 ; i=i+d) { if (a[i]<a[i-d]){ a[0] = a[i]; for ( j = i-d; j>0 && a[j] >a[0] ; j= j-d) { a[j+d] = a[j]; } a[j+d] = a[0]; } } } } }
标签:sort,temp,int,void,希尔,排序 From: https://www.cnblogs.com/jixian/p/17154930.html