int Partition(int A[],int low ,int high)
{
int pivot = A[low];
while (low < high )
{
while (low<high&&A[high]>=pivot)
{
high -- ;
}
A[low] = A[high];
while (low < high&&A[low]<=pivot)
{
low++;
}
A[high] = A[low];
}
A[low] = pivot;
return low;
}
void QuickSort(int A[],int low ,int high)
{
if (low<high)
{
int pos = Partition(A,low,high);
QuickSort(A,low,pos-1);
QuickSort(A,pos+1,high);
}
}
快速排序
最新推荐文章于 2024-07-17 10:35:12 发布