Partition

Here, partition(data,i,j,l) partitions array elements A[i] through A[j] around A[l]. It returns k, the index where the partition element ends up.

$\begin{array}
{ccccccc}
i&\ldots& k-1& k& k+1& \ldots& j\end{array}$

After partitioning, element k is in its correct, sorted place, all the elements from i to k-1 are less than A[k], and all the elements from k+1 to j are greater than A[k] (and transitively, elements i through k-1).


next up previous
Next: Analysis Up: PROBLEM WITH QUICKSORT Previous: Quicksort Algorithm