2019.2.30 public static <T>int partition(T[] list, int first, int last, Comparator<T> comparator){ T pivot = list[first]; int low = first + 1; int high = last; while(high > low){ while(low <= high && comparator.compare(list[low], pivot) <= 0) low++; while(low <= high && comparator.compare(list[high],pivot) > 0) high--; if(high > low){ T tmp = list[high]; list[high] = list[low]; list[low] = tmp; } } while (high > first && comparator.compare(list[high], pivot) >= 0) high--; if(comparator.compare(pivot, list[high]) > 0){ list[first] = list[high]; list[high] = pivot; return high; }else{ return first; } }