private static int partition(Comparable[] a, int left, int right) {
        int leftPos = left;
        int rightPos = right + 1;

        Comparable v = a[left];

        while(true) {
            while(less(a[++leftPos], v))
                if (leftPos == right) break;

            while(less(v, a[--rightPos]))
                if (rightPos == left) break;

            if (leftPos >= rightPos) break;

            exchange(a, leftPos, rightPos);
        }

        exchange(a, left, rightPos);

        return rightPos;
    }