参考:《算法》第四版.P182~187
一. 代码实现:
package com.odyssey.app.algorithm.sort;
import com.alibaba.fastjson.JSONObject;
/**
* @author Dingsheng Huang
* @date 2020/3/13 19:24
*/
public class QuickSort {
public static void sort(int[] arr, int lo, int hi) {
if (lo >= hi) {
return;
}
// 以lo为分界线, 将数据分为两拨,并返回切分完的分界点,在递归排序分界点 前后的数据
int temp = partition(arr, lo, hi);
sort(arr, lo, temp - 1);
sort(arr, temp + 1, hi);
}
private static int partition(int[] arr, int lo, int hi) {
int i = lo;
int j = hi + 1;
int target = arr[lo];
// 双指针扫描
while (true) {
while (arr[++i] < target) {
if (i == hi) {
break;
}
}
while (arr[--j] > target) {
if (j == lo) {