int Partition(int a[], int p, int q)
{
int i = p - 1, j = p, pivot = a[q];
int t;
while (j <= q-1)
{
if (a[j] >= pivot)
{
i++;
t = a[i]; a[i] = a[j]; a[j] = t;
}
j++;
}
t = a[i + 1]; a[i + 1] = a[q]; a[q] = t;
return i + 1;
}
void QuickSort(int a[], int p, int q)
{
if (p < q)
{
int pivot = Partition(a, p, q);
QuickSort(a, p, pivot - 1);
QuickSort(a, pivot + 1, q);
}
}
快排快排快排
最新推荐文章于 2024-08-14 11:57:07 发布