步骤:
- 确定分界点:左边界、右边界、中间、随机
- 调整区间:≤x的在x左边、≥x的在x右边
- 递归处理,左右两端

解决思路1:
- 创建两个数组,a[],b[]
- 在a[]和b[]中存放值
- 先把a[]中的数放入q[]中,然后放b[]

缺点:需要额外开发两个数组
解决思路2:(优美方法)
public class Quick_sort {
static int n;
static int[] q ;
public static void main(String[] args) {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
try {
System.out.println("输入n:");
n = Integer.parseInt(bf.readLine());
q = new int[n];
for (int i = 0; i < n; i++) {
System.out.println("输入第"+(i+1)+"个数据:");
q[i] = Integer.parseInt(bf.readLine());
}
} catch (IOException e) {
e.printStackTrace();
}
Quick_sort.quick_sort(q,0,n-1);
for(int n:q){
System.out.println(n);
}
}
public static void quick_sort(int [] q,int l,int r){
if (l>=r) return;
int i = l - 1;
int j = r + 1;
int x = q[l];
while (i<j){
do {
i++;
}while (q[i]<x);
do {
j--;
}while (q[j]>x);
if (i<j){
int t = q[i];
q[i] = q[j];
q[j] = t;
}
}
quick_sort(q,l,j);
quick_sort(q,j+1,r);
}
}