class QuickSort {

	public static <T> int partition(T[] array, int startIndex, int endIndex,
			Comparator<T> comparator, int pivotIndex) {
		if (pivotIndex == -1) {
			pivotIndex = getRandomPivotIndex(startIndex, endIndex);
		}

		com.github.kowshik.bigo.common.ArrayUtils.swap(array, pivotIndex, endIndex);
		int swapIndex = startIndex - 1;
		for (int index = startIndex; index <= endIndex - 1; index++) {
			if (comparator.compare(array[index], array[endIndex]) <= 0) {
				swapIndex++;
				com.github.kowshik.bigo.common.ArrayUtils.swap(array, swapIndex, index);
			}
		}

		com.github.kowshik.bigo.common.ArrayUtils.swap(array, swapIndex + 1, endIndex);
		return swapIndex + 1;
	}

}