?视频讲解地址:【手把手带你写十大排序】5.快速排序(Java语言)_哔哩哔哩_bilibili
代码:
public class QuickSort {
public void sortFunction(int[] array, int low, int high) {
if (low < high) {
int pivot = array[low];
int i = low;
int j = high;
while (i < j) {
while ((i < j) && array[j] > pivot) {
j--;
}
if (i < j) {
array[i] = array[j];
i++;
}
while ((i < j) && array[i] < pivot) {
i++;
}
if (i < j) {
array[j] = array[i];
j--;
}
}
array[i] = pivot;
sortFunction(array, low, i - 1);
sortFunction(array, i + 1, high);
}
}
}