int partition(int *arr, int low, int high)
{
int pivot = arr[low];
while(low < high)
{
while(low < high && arr[high] >= pivot)
--high;
if(low < high)
arr[low] = arr[high];
while(low < high && arr[low] <= pivot)
++ low;
if(low < high)
arr[high] = arr[low];
}
arr[low] = pivot;
return low;
}
void quickSort(int *arr, int L, int R){
if(L < R){
int p = partition(arr, L, R);
quickSort(arr, L, p - 1);
quickSort(arr, p + 1, R);
}
}
经典快速排序
最新推荐文章于 2022-08-17 22:15:00 发布