[Home]
[Chapter]
[Contents]
[Previous Algorithm]
[Next Algorithm]


Quicksort (with bounded stack usage)


procedure sort( var r : ArrayToSort; lo, up : integer ); var i, j : integer; tempr : ArrayEntry; begin while up>lo do begin i := lo; j := up; tempr := r[lo]; {*** Split file in two ***} while i<j do begin while r[j].k > tempr.k do j := j-1; r[i] := r[j]; while (i<j) and (r[i].k<=tempr.k) do i := i+1; r[j] := r[i] end; r[i] := tempr; {*** Sort recursively ***} sort(r,lo,i-1); lo := i+1 end end;

C source (413.sort.c) Pascal source (413.sort.p)



© Addison-Wesley Publishing Co. Inc.