アルゴリズム(第4版)ヒルソート

560 ワード

public static Comparable[] sort(Comparable[] intLIst) {

        int h = 1;
        int n = intLIst.length;
        while (h < n / 2) {
            h = 2 * h + 1;
        }
        h = (h-1)/2;
        int max = h;

        while (h >= 1) {

            for (int i = h; i < n; i++) {

                for (int j = i; j >= h && less(intLIst[j], intLIst[j-h]); j -= h) {
                    exch(intLIst, j, j - h);

                }
            }

            h = (h-1)/2;

        }

        return intLIst;

    }