public static void shellSort(Comparable[] array) {
        int h = 1;

        while(h < array.length / 3) {
            h = h * 3 + 1; //1, 4, 13 and so on.
        }

        while(h > 0) {
            for(int i = h; i < array.length; i++) {
                for (int j = i; j >= h && array[j].compareTo(array[j - 1]) < 0; j -= h) {
                    exchange(array, j, j - h);
                }
            }
            h = h/3;
        }
    }