public static <E> void sort(E[] array, Comparator<? super E> comparator) {
        for (int i = 1; i < array.length; i++) {
            int j = i - 1;
            E key = array[i];
            while (j >= 0 && comparator.compare(array[j], key) >= 0) {
                array[j + 1] = array[j];
                j--;
            }
            array[j + 1] = key;
        }
    }