package uk.co.johnjtaylor.sorts;

import uk.co.johnjtaylor.Sort;

public class QuickSort<T extends Comparable<T>> extends Sort<Integer> {

	@Override
	public Object sort(Object input) {
		T[] array = null;
		if(input instanceof Comparable<?>[]) {
			array = (T[]) input;
		}
		
		T[] result = qSort(array, 0, array.length-1);
		return result;
	}
	

	public T[] qSort(T[] array, int lo, int hi) {
		T pivotVal = array[lo];
		Integer left = lo;
		Integer right = hi;
		while(left <= right) {
			if(array instanceof String[]) { // Current array is Strings
				while(((String) array[left]).compareToIgnoreCase((String) pivotVal) < 0) {
					left++;
				}
				while(((String)array[right]).compareToIgnoreCase((String) pivotVal) > 0) {
					right--;
				}
			}
			else { // Current array is NOT Strings
				while(array[left].compareTo(pivotVal) < 0) {
					left++;
				}
				while(array[right].compareTo(pivotVal) > 0) {
					right--;
				}
			}
			
			if(left.compareTo(right) <= 0) {
				T temp = array[left];
				array[left] = array[right];
				array[right] = temp;
				left++;
				right--;
			}
		}
		if(right.compareTo(lo) > 0) {
			qSort(array, lo, right);
		}
		if(left.compareTo(hi) < 0) {
			qSort(array, left, hi);
		}
		
		return array;
	}
}

@@ -275,16 +275,154 @@
 input;%0D%0A
+%09%09%7D else %7B%0D%0A%09%09%09throw new UnsupportedOperationException(this.getClass().getName() + %22 does not support non-array sorts in this version%22);%0D%0A
 %09%09%7D%0D%0A%09%09%0D

Throw UnsupportedOp exception for non-arrays until implemented