public class QuickSort {
public static int partition(int[] arr,int start,int end){
int part=arr[start];
int locate=start;
while(start<end){
while(end>start&&arr[end]>part)end--;
if(end<=start){
break;
}
arr[locate]=arr[end];
locate=end;
while(start<end&&arr[start]<=part) start++;
if(start>=end){
break;
}
arr[locate]=arr[start];
locate=start;
}
arr[locate]=part;
return locate;
}
public static void quickSort(int[] arr,int start,int end){
if(start>=end) return;
int mid=partition(arr,start,end);
quickSort(arr,start,mid-1);
quickSort(arr,mid+1,end);
}
}
快速排序
最新推荐文章于 2022-05-01 09:00:00 发布