来一段快速排序的java代码
时间: 2023-03-14 16:28:35 浏览: 75
快速排序java代码
public void quickSort(int[] array, int lowerIndex, int higherIndex) {
int i = lowerIndex;
int j = higherIndex;
int pivot = array[lowerIndex + (higherIndex - lowerIndex) / 2]; while (i <= j) {
while (array[i] < pivot) {
i++;
}
while (array[j] > pivot) {
j--;
}
if (i <= j) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
i++;
j--;
}
}
if (lowerIndex < j)
quickSort(array, lowerIndex, j);
if (i < higherIndex)
quickSort(array, i, higherIndex);
}
阅读全文