shell排序优化算法
public void sort(int arr[]){
int h = 1;
while(h * 3 < arr.length) h = h * 3 + 1;
for (int gap = h; gap > 0; gap = (gap -1) /3) {
for (int i = gap; i < arr.length; i++) {
for (int i1 = i; i1 > i - 1; i1 -= gap) {
if(arr[i1] < arr[i1 - gap])
swap(arr,i1, i1 - gap);
}
}
}
}
使用的是knuth算出间隔gap
while(h * 3 < arr.length) h = h * 3 + 1;