/** * Sorts the given array slice in natural order. This method uses the merge sort * algorithm, but falls back to insertion sort for small arrays. * @param fromIndex start index (inclusive) * @param toIndex end index (exclusive) */ public static <T extends Comparable<? super T>> void mergeSort(T[] a, int fromIndex, int toIndex) { if (toIndex-fromIndex <= 1) return; getSorter(a).mergeSort(fromIndex, toIndex-1); }
/** * Sorts the given array slice using the {@link Comparator}. This method uses the merge sort * algorithm, but falls back to insertion sort for small arrays. * @param fromIndex start index (inclusive) * @param toIndex end index (exclusive) */ public static <T> void mergeSort(T[] a, int fromIndex, int toIndex, Comparator<? super T> comp) { if (toIndex-fromIndex <= 1) return; //System.out.println("SORT: " + (toIndex-fromIndex)); getSorter(a, comp).mergeSort(fromIndex, toIndex-1); }
/** * Sorts the given array slice using the {@link Comparator}. This method uses the quick sort * algorithm, but falls back to insertion sort for small arrays. * @param fromIndex start index (inclusive) * @param toIndex end index (exclusive) */ public static <T> void quickSort(T[] a, int fromIndex, int toIndex, Comparator<? super T> comp) { if (toIndex-fromIndex <= 1) return; getSorter(a, comp).quickSort(fromIndex, toIndex-1); }
/** * Sorts the given array slice in natural order. This method uses the quick sort * algorithm, but falls back to insertion sort for small arrays. * @param fromIndex start index (inclusive) * @param toIndex end index (exclusive) */ public static <T extends Comparable<? super T>> void quickSort(T[] a, int fromIndex, int toIndex) { if (toIndex-fromIndex <= 1) return; getSorter(a).quickSort(fromIndex, toIndex-1); }
/** * Sorts the given array slice using the {@link Comparator}. This method uses the insertion sort * algorithm. It is only recommended to use this algorithm for partially sorted small arrays! * @param fromIndex start index (inclusive) * @param toIndex end index (exclusive) */ public static <T> void insertionSort(T[] a, int fromIndex, int toIndex, Comparator<? super T> comp) { if (toIndex-fromIndex <= 1) return; getSorter(a, comp).insertionSort(fromIndex, toIndex-1); }
/** * Sorts the given array slice in natural order. This method uses the insertion sort * algorithm. It is only recommended to use this algorithm for partially sorted small arrays! * @param fromIndex start index (inclusive) * @param toIndex end index (exclusive) */ public static <T extends Comparable<? super T>> void insertionSort(T[] a, int fromIndex, int toIndex) { if (toIndex-fromIndex <= 1) return; getSorter(a).insertionSort(fromIndex, toIndex-1); }