希尔排序

希尔排序

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;
        }
    }

你可能感兴趣的:(希尔排序)