static int Paration(int *a, int nstart, int nend)
{
int x = a[nend];
int temp = 0;
int i = nstart - 1;
for(int j = nstart; j < nend; j++)
{
if(a[j] < x)
{
temp = a[j];
i = i+1;
a[j] = a[i];
a[i] = temp;
}
}
temp = a[i + 1];
a[i + 1] = x;
a[nend] = temp;
return i + 1;
}
void Quick_Sort(int *a, int nstart, int nend)
{
if(nstart < nend)
{
int nmid = Paration(a, nstart, nend);
Quick_Sort(a, nstart, nmid -1 );
Quick_Sort(a, nmid + 1, nend);
}
return;
}
排序算法的数组实现 -- 快速排序(四)
最新推荐文章于 2024-08-22 21:24:01 发布