mezi c1 a c2 to urcite nemuze byt protoze tam mam cyklus repeat until takze by se to provedlo vicekrat. Tady je jeste ta unita:
unit trideni;
interface
uses crt,dos;
const m=10000;
type Tpole=array[1..m]of integer;
var p:Tpole;
function Cas:real;
procedure nacti(var p:Tpole;n:integer);
procedure tisk(var p:Tpole;n:integer);
procedure BubbleSort(var p:Tpole;n:integer);
procedure HeapSort(var p:Tpole;n:integer);
procedure QuickSort(var p:Tpole;n:integer);
procedure SelectSort(var p:Tpole;n:integer);
procedure ShakerSort(var p:Tpole;n:integer);
implementation
function Cas:real;
var h,m,s,ss:word;
hr:real;
begin
gettime(h,m,s,ss);
hr:=h;
cas:=hr*3600+m*60+s+ss/100;
end;
procedure nacti(var p:Tpole;n:integer);
var i:integer;
begin
randomize;
for i:=1 to n do
p[i]:=random(1000)+1;
end;
procedure tisk(var p:Tpole;n:integer);
var i:integer;
begin
for i:=1 to n do
write(p[i]:5);
end;
procedure BubbleSort(var p:Tpole;n:integer);
var i,j,x:integer;
begin
for i:=1 to n-1 do
for j:=1 to n-1 do
if p[j] > p[j+1] then begin
x:=p[j];
p[j]:=p[j+1];
p[j+1]:=x;
end;
end;
procedure HeapSort(var p:Tpole;n:integer);
var k,r,pom:integer;
procedure zarazeni;
var i,j:integer;
begin
i:=k;
j:=2*i;
pom:=p[i];
while j<=r do begin
if j<r then
if p[j]<p[j+1] then inc(j);
if pom>p[j] then break;
p[i]:=p[j];
i:=j;
j:=2*i;
end;
p[i]:=pom;
end;
begin
k:=(n div 2)+1;
r:=n;
while k>1 do
begin
dec(k);
zarazeni;
end;
while r>1 do
begin
pom:=p[1];
p[1]:=p[r];
p[r]:=pom;
dec(r);
zarazeni;
end;
end;
procedure QuickSort(var p:Tpole;n:integer);
procedure Trideni(LL,RR:longint);
var x,pom:integer;
L,R:longint;
begin
x:=p[(LL+RR) div 2];
L:=LL;
R:=RR;
repeat
while p[L] < x do inc(L);
while x < p[R] do dec(R);
if L<=R then begin
pom:=p[L];
p[L]:=p[R];
p[R]:=pom;
inc(L);
dec(R);
end;
until L>R;
if LL<r then Trideni(LL,R);
if L<RR then Trideni(L,RR);
end;
begin
Trideni(1,n);
end;
procedure SelectSort(var p:Tpole;n:integer);
var i,j,min,pom:integer;
begin
for i:=1 to n-1 do
begin
min:=p[i];
for j:=i+1 to n do
begin
if min>p[j] then
begin
min:=p[j];
pom:=j;
end;
end;
p[pom]:=p[i];
p[i]:=min;
end;
end;
procedure ShakerSort(var p:Tpole;n:integer);
var j,k,L,R,x:integer;
begin
L:=2;R:=n;k:=n;
repeat
for j:=R downto L do
if p[j-1]>p[j] then begin
x:=p[j-1];
p[j-1]:=p[j];
p[j]:=x;
k:=j;
end;
L:=k+1;
for j:=L to R do
if p[j-1]>p[j] then begin
x:=p[j-1];
p[j-1]:=p[j];
p[j]:=x;
k:=j;
end;
R:=k-1;
until L>R;
end;
begin
end.