szostak.pev.pl
home
aktualne projekty
szkolne projekty
kontakt
QUICKSORT
Program quickSort;
var
tab :array[0..100] of integer;
i: byte;
elements:byte;
Procedure qSort(var tab : array of integer; left:byte; right:byte);
var
i,j : byte;
bElement:integer;
tmp:integer;
begin
bElement:=tab[(left+right) div 2];
i:=left;
j:=right;
while(i<=j) do
begin
while(tab[i]
while(tab[j]>bElement) do j:=j-1;
if(i<=j) then
begin
tmp:=tab[i];
tab[i]:=tab[j];
tab[j]:=tmp;
i:=i+1;
j:=j-1;
end;
end;
if(j>left) then qSort(tab, left, j);
if(i
end;
begin
randomize();
elements:=100;
for i:=0 to elements do tab[i]:=random(100);
qSort(tab,0,elements);
for i:=0 to elements do writeln(tab[i]);
readln;
end.
Darmowy hosting
zapewnia PRV.PL