希尔排序
public static void shellSort(int[] arr) {
int len = arr.length;
int tmp, gap = len / 2;
while (gap > 0) {
for (int i = gap; i < len; i++) {
tmp = arr[i];
int pre = i - gap;
while (pre >= 0 && arr[pre] > tmp) {
arr[pre + gap] = arr[pre];
pre -= gap;
}
arr[pre + gap] = tmp;
}
gap /= 2;
}
}
网友评论