递归太深(数据量过大,100万以上)会出现栈满的问题,改用非递归:
public static void quickSortByMoreData(int arr[]) {
int left = 0;
int right = arr.length - 1;
Stack<Integer> stack = new Stack<Integer>();
stack.push(left);
stack.push(right);
while(!stack.isEmpty()) {
int r = stack.pop();
int l = stack.pop();
int s = getStart(arr, l, r);
if(s-1 > l) {
stack.push(l);
stack.push(s-1);
}
if(s+1 < r) {
stack.push(s+1);
stack.push(r);
}
}