| 792 | } |
| 793 | |
| 794 | private <E extends T> int partition(E[] values, int left, int right, int pivotIndex) { |
| 795 | E pivotValue = values[pivotIndex]; |
| 796 | |
| 797 | values[pivotIndex] = values[right]; |
| 798 | values[right] = pivotValue; |
| 799 | |
| 800 | int storeIndex = left; |
| 801 | for (int i = left; i < right; i++) { |
| 802 | if (compare(values[i], pivotValue) < 0) { |
| 803 | ObjectArrays.swap(values, storeIndex, i); |
| 804 | storeIndex++; |
| 805 | } |
| 806 | } |
| 807 | ObjectArrays.swap(values, right, storeIndex); |
| 808 | return storeIndex; |
| 809 | } |
| 810 | |
| 811 | /** |
| 812 | * Returns the {@code k} greatest elements of the given iterable according to |