private static int setInOrderPosition(Integer[] a, int pos, int startIndex, int endIndex) {
        swap(a, pos, endIndex);
        int firstSmallerValuePosition = startIndex;
        for (int i = startIndex; i <= endIndex; i++) {
            if (a[i] >= a[endIndex]) {
                swap(a, i, firstSmallerValuePosition++);
            }
        }

        return firstSmallerValuePosition - 1;
    }