private static <T extends Comparable<? super T>> void sort(T[] a, int n) {
        int inc = 1;
        do {
            inc *= 3;
            inc++;
        } while (inc <= n);

        do {
            inc /= 3;
            for (int i = inc; i < n; i++) {
                T v = a[i];
                int j = i;
                while (a[j - inc].compareTo(v) < 0) {
                    a[j] = a[j - inc];
                    j -= inc;
                    if (j < inc) {
                        break;
                    }
                }
                a[j] = v;
            }
        } while (inc > 1);
    }
private static < T extends Comparable < ? super T > > void sort ( T [ ] a , int n ) { int inc = 1 ; do { inc *= 3 ; inc ++ ; } while ( inc <= n ) ; do { inc /= 3 ; for ( int i = inc ; i < n ; i ++ ) { T v = a [ i ] ; int j = i ; while ( a [ j - inc ] . compareTo ( v ) < 0 ) { a [ j ] = a [ j - inc ] ; j -= inc ; if ( j < inc ) { break ; } } a [ j ] = v ; } } while ( inc > 1 ) ; }
Sorts the specified array into descending order. It is based on Shell
sort, which is very efficient because the array is almost sorted by
heapifying.