Quicksort

    public static void quicksort(int[] items) {
        quicksort(items, 0, items.length - 1);
    }

    private static void quicksort(int[] items, int left, int right) {
        int pivotindex = (left + right) / 2;

        // curr will be the final position of the pivot item.
        int curr = partition(items, left, right, pivotindex);

        if ((curr - left) > 1) {
            quicksort(items, left, curr - 1); // Sort left partition
        }
        if ((right - curr) > 1) {
            quicksort(items, curr + 1, right); // Sort right partition
        }
    }

    private static int partition(int[] items, int left, 
                                 int right, int pivotindex) {

        int pivot = items[pivotindex];
        swap(items, pivotindex, right); // Stick pivot at end
        pivotindex = right; // remember where it is.

        right--;

        while (left <= right) { // Move bounds inward until they meet
            while (items[left] < pivot) {
                left++;
            }
            while ((right >= left) && (items[right] >= pivot)) {
                right--;
            }
            if (right > left) {
                swap(items, left, right); // Swap out-of-place values
            }
        }
        swap(items, left, pivotindex); // Put pivot in place

        return left; // Return first position in right partition
    }