QuickSort

Kod szybkiego sortowania tablicy w Pascalu (z randomizowanym wyborem elementu dzielącego, lecz bez pozostałych usprawnień).

procedure qsortdiv(var tab:array of longint;left,right:longint);
var i,j,x,temp:longint;
begin
   i:=left;
   j:=right;
   x:=tab[(left+right) div 2]; {element środkowy jest elementem osiowym}
   repeat
      while tab[i]<x do inc(i);
      while tab[j]>x do dec(j);
      if i<=j then begin
         temp:=tab[i];
         tab[i]:=tab[j];
         inc(i);
         tab[j]:=temp;
         dec(j);
      end;
   until i>j;
   if left<j then qsortdiv(tab,left,j);
   if i<right then qsortdiv(tab,i,right);
end;
O ile nie zaznaczono inaczej, treść tej strony objęta jest licencją Creative Commons Attribution-ShareAlike 3.0 License