复制代码
public class Test_A30 {
public void quickSort(int[] arr,int low,int hight){
if(low<hight){
int pivot=partition(arr,low,hight);
quickSort(arr,low,pivot-1);
quickSort(arr,pivot+1,hight);
}
}
private int partition(int[] arr,int low,int high){
int pivot=arr[high];
int i=low-1;
for(int j=low;j<high;j++){
if(arr[j]<pivot){
i++;
int temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
int temp=arr[i+1];
arr[i+1]=arr[high];
arr[high]=temp;
return i+1;
}
public static void main(String[] args){
Test_A30 test_30=new Test_A30();
int[] arr={24,6,87,23,1,45};
test_30.quickSort(arr,0,arr.length-1);
for(int num:arr){
System.out.println(num+"");
}
}
}