Cormen Quicksort
void quick_sort(A,p,r)
{
if (r - p > 1)
{
q = Partition(A,p,r);
quick_sort(A,p,q);
quick_sort(A,q+1,r);
}
}
|
size_t Partition(A,p,r)
{
i = p;
for (j = p; j < r-1; ++j)
{
if (A[j] <= A[r-1])
{
swap(A[i],A[j]);
++i;
}
}
// the last place requires no test:
swap(A[i],A[r-1]);
return i;
}
|