public static void main(String[]args){
int[]arr={12,23,6,7,56,8,5};
quicksort(arr,0,arr.length-1);
}
public static void quicksort(int arr[],int start,int end){
if(start<end){
int middle=getMiddle(arr,start,end);
quicksort(arr,start,middle-1);
quicksort(arr,middle+1,end);
}
}
public static int getMiddle(int[]arr,int start,int end){
int left=start;
int right=end;
int key=arr[start];
int temp;
while(left<right){
left<right;
while(arr[right]>=key){
right--;
}
while(arr[left]<=key){
right++;
}
temp=arr[right];
arr[right]=arr[left];
arr[left]=temp;
if(left=right){
temp=arr[right];
arr[right]=key;
arr[start]=temp;
}
return right;
网友评论