protected int partition(int[] array, int startIndex, int endIndex) {

        int pivot = pickPivot(Arrays.copyOfRange(array, startIndex, endIndex));
        int left = startIndex-1 ;
        int right = endIndex+1 ;

        while (true) {
            left++;
            while ( left< endIndex && array[left] < pivot) {
                left++;
            }
            right--;
            while (right>startIndex && array[right] > pivot) {
                right--;
            }
            if (left < right)
                swapElements(array, left, right);
            else
                return right;
        }
    }