还有些细节要想一下
import java.util.*;
public class Main {
public void swap(int[] arr, int a, int b){
int tmp = arr[a];
arr[a] = arr[b];
arr[b] = tmp;
return ;
}
public void quickSort(int[] arr, int l, int r){
int ll = l, rr = r;
if(l>=r) return ;
int idx = arr[l];
while (l<r){
while(l<r&&idx<arr[r]){
r--;
}
while(l<r&&idx>arr[l]){
l++;
}
if(l<r) swap(arr,l,r);
}
arr[l] = idx;
quickSort(arr,ll,l-1);
quickSort(arr,l+1,rr);
return ;
}
public static void main(String[] args){
int[] arr = new int[]{4,1,8,5,3,2,9,10,6,7};
Main m = new Main();
m.quickSort(arr,0,9);
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+",");
}
}
}
|