private static <T extends Comparable<T>> int partition(List<T> list, int left, int right)
    {
        int i = left, j = right;
        T temp;
        T pivot = list.get((left + right)/2);
        
        while (i <= j)
        {
            while (list.get(i).compareTo(pivot) < 0)
            {
                i++;
            }
            while (list.get(j).compareTo(pivot) > 0)
            {
                j--;
            }
            if (i <= j)
            {
                temp = list.get(i);
                list.set(i, list.get(j));
                list.set(j, temp);
                i++;
                j--;
            }
        }
        
        return i;
    }