@Override
    public int partition(Comparable[] a, int left, int right) {
        int x = left;
        int y = right + 1;
        int v = left;

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

            while (less(a[v], a[--y])) {
                if (y <= left) {
                    break;
                }
            }

            if (x >= y) {
                break;
            }

            swap(a, x, y);
        }

        swap(a, v, y);
        return y;
    }