//快排
public void quickSort(int[] arr,int start,int end){
if (start>=end||arr.length<=1){
return ;
}
int low = start;
int high = end;
int mid = arr[low];
while (low<high){
while (arr[high]>=mid && low < high){
high--;
}
arr[low]=arr[high];
while (arr[low]<mid && low < high){
low++;
}
arr[high]=arr[low];
}
arr[low]=mid;
quickSort(arr,start,low-1);
quickSort(arr,high+1,end);
};
@Test
public void test014() throws Exception{
//快排
int[] arr = {4, 3, 5, 3, 6, 2, 8, 1, 9,3,5,1,2,3,6,8,0,8,7,6,5,4};
quickSort(arr,0,arr.length-1);
System.out.println(Arrays.toString(arr));
}
快速排序法
最新推荐文章于 2025-04-25 18:07:04 发布