package com.stephenramthun.algorithms.sorting;

/**
 * Quicksort based on the Hoare partition scheme.
 * Uses insertion sort as a subroutine when subarray to sort is shorter than a specified limit.
 *
 * @author  Stephen Ramthun
 * @see     <a href="https://en.wikipedia.org/wiki/Quicksort#Hoare_partition_scheme">Hoare Partition Scheme</a>
 */

public class Quicksort {

    private static final int LIMIT = 50;

    /**
     * Sorts a given array of integers in ascending order.
     *
     * @param array     Array of integers to sort.
     */
    public static void sort(int[] array) {
        sort(array, 0, array.length - 1);
    }

    private static void sort(int[] array, int left, int right) {
        if (right - left > LIMIT) {
            int part = partition(array, left, right);
            sort(array, left, part);
            sort(array, part + 1, right);
        } else {
            InsertionSort.sort(array, left, right + 1);
        }
    }

    private static int partition(int[] array, int left, int right) {
        int pivot = array[left];
        int i     = left - 1;
        int j     = right + 1;

        while (i < j) {
            do {
                i++;
            } while (array[i] < pivot);

            do {
                j--;
            } while (array[j] > pivot);

            if (i < j) {
                Utility.swap(array, i, j);
            }
        }

        return j;
    }
}

@@ -641,35 +641,465 @@
    p
-rivate static void sort(int
+ublic static void sort(Comparable%5B%5D array) %7B%0A        sort(array, 0, array.length - 1);%0A    %7D%0A%0A    private static void sort(int%5B%5D array, int left, int right) %7B%0A        if (right - left %3E LIMIT) %7B%0A            int part = partition(array, left, right);%0A            sort(array, left, part);%0A            sort(array, part + 1, right);%0A        %7D else %7B%0A            InsertionSort.sort(array, left, right + 1);%0A        %7D%0A    %7D%0A%0A    private static void sort(Comparable
 %5B%5D a
@@ -1691,16 +1691,16 @@
    j--;%0A
-
         
@@ -1821,24 +1821,747 @@
 %0A        %7D%0A%0A
+        return j;%0A    %7D%0A%0A    @SuppressWarnings(%22unchecked%22)%0A    private static int partition(Comparable%5B%5D array, int left, int right) %7B%0A        Comparable pivot = array%5Bleft%5D;%0A        int i = left - 1;%0A        int j = right + 1;%0A%0A        while (i %3C j) %7B%0A            int comparison = array%5Bi%5D.compareTo(pivot);%0A%0A            do %7B%0A                comparison = array%5Bi%5D.compareTo(pivot);%0A                i++;%0A            %7D while (comparison %3E 0);%0A%0A            comparison = array%5Bj%5D.compareTo(pivot);%0A%0A            do %7B%0A                comparison = array%5Bj%5D.compareTo(pivot);%0A                j--;%0A            %7D while (comparison %3E 0);%0A%0A            if (i %3C j) %7B%0A                Utility.swap(array, i, j);%0A            %7D%0A        %7D%0A%0A
         retu

Add methods for sorting arrays of Comparable objects.