public class QuickSort{
?? ?public? void sort(int[] arr,int low,int high){
?? ??? ?int pos=0;
?? ??? ?if(low<high){
?? ??? ??? ?pos=part(arr,low,high);
?? ??? ??? ?sort(arr,low,pos-1);
?? ??? ??? ?sort(arr,pos+1,high);
?? ??? ?}
?? ?}
?? ?public? int part(int[] arr,int low,int high){
?? ??? ?//将枢轴位置的记录保存下来
?? ??? ?int temp = arr[high];
?? ??? ?while(low<high){
?? ??? ??? ?while(low<high&&arr[low]<=temp){
?? ??? ??? ??? ?low++;
?? ??? ??? ?}
?? ??? ??? ?if(low<high){
?? ??? ??? ???????? arr[high--]=arr[low];
?? ??? ??? ?}
?? ??? ??? ?while(low<high&&arr[high]>temp){
?? ??? ??? ??? ?high--;
?? ??? ??? ?}
?? ??? ??? ?if(low<high){
?? ??? ??? ???????? arr[low++]=arr[high];
?? ??? ??? ?}
?? ??? ?}
?? ??? ?//找到最终的枢轴的位置,将保存的记录放到改位置
?? ??? ?arr[high]=temp;
?? ??? ?return high;
?? ?}
}