(* From: ROLAND WODITSCH Subj: QUICK SORT *) UNIT QSort5; INTERFACE TYPE OrdFunction = FUNCTION(VAR a,b):BOOLEAN; PROCEDURE Sortiere(VAR SortArray; Elementgroesse,LoIndex,HiIndex: word; SortKleiner: OrdFunction; von,bis:word); { SortArray field to sort } { LoIndex the lowest, } { HiIndex the highest fieldindex like in the fielddeklarartion } { OrdAdr the funktion from typ OrdFunction (s.o.) } { von, bis the sortarea } { befor calling (not befor bind!) your have to define a } { asymmetric order funktion : } { function IrgendEinName(VAR x,y : TypDerFeldElemente):boolean } { example: (*$F+*) function kleiner(VAR x,y: integer):boolean; } { begin kleiner:=xi0 then Swap(i0^,m0^,ElementGroesse); inc(i,i0) end; (* WHILE i *) EXIT: end; (* E_Sort *) procedure Sort(von, bis : word); (* Rekursive Quicksort *) label EXIT; var i, j : word; begin if bis-von<6 then begin E_Sort(von,bis); goto EXIT end; i:=von; j:=bis; m0:=Element((i+j) SHR 1); move(m0^,Mitte^,ElementGroesse); i0:=Element(i); j0:=Element(j); while i<=j do begin while SortKleiner(i0^,Mitte^) do inc(i,i0); while SortKleiner(Mitte^,j0^) do dec(j,j0); if i<=j then begin if i<>j then Swap(i0^,j0^,ElementGroesse); inc(i,i0); dec(j,j0) end (* if i<=j *) end; (* while i<=j *) if bis-i