private static void quickSort(int[] arr, int i, int length) {
if (i < length) {
// 得到中间数据索引
int middle = getMiddleData(arr, i, length);
// 对左边数据进行排序
quickSort(arr, 0, middle - 1);
// 对右边数据进行排序
quickSort(arr, middle + 1, length);
}
}
private static int getMiddleData(int[] arr, int i, int length) {
// 记录数组的最低位和最高位索引
int low = i;
int high = length;
// 记录数组的第一个元素作为中轴元素
int temp = arr[i];
while (low < high) {
while (low < high && temp <= arr[high]) {
high--;
}
arr[low] = arr[high];
while (low < high && arr[low] <= temp) {
low++;
}
arr[high] = arr[low];