nextupprevious
Next:9.6.3 Quicksort: Average Case AnalysisUp:9.6 Quick SortPrevious:9.6.1 Algorithm:

9.6.2 Algorithm for Partitioning

int partition (int i; int j; key-type pivot);

        /* partitions the elements a[k] ... a[j],

        wrt the pivot and returns the position k  */

    {

        int$ \ell$, r;

        {

$ \ell$ = i; /*$ \ell$ starts from left end */

            r = j; /*r starts from right end */

            do

                swap the records a[$ \ell$] and a[r];

                while (a[$ \ell$] . key < pivot)

$ \ell$$ \ell$ + 1;

                while (a[r] . key $ \geq$ pivot)

                    r = r - 1;

                while($ \ell$$ \leq$r);

                    return ($ \ell$);

            }

    }


Figure 9.3: Quicksort applied to a list of 10 elements
\begin{figure}%\centerline{\psfig{figure=figures/Fquick.ps,height=5in}}\end{figure}

eEL,CSA_Dept,IISc,Bangalore