这让我发疯,我知道这是一次性错误导致的,但由于某种原因,我的分区函数没有正确分区。我究竟做错了什么?
public static int partition(int numbers[], int lhs, int rhs) {
int pivot = numbers[(rhs - lhs) / 2];
int lIndex = lhs - 1;
int rIndex = rhs + 1;
while (true) {
while (numbers[++lIndex] < pivot);
while (numbers[--rIndex] > pivot);
if (lIndex > rIndex) break;
int temp = numbers[lIndex];
numbers[lIndex] = numbers[rIndex];
numbers[rIndex] = temp;
}
return lIndex;
}