Pagini recente » Cod sursa (job #3279321) | Cod sursa (job #2559129) | Cod sursa (job #958742) | Cod sursa (job #1420229) | Cod sursa (job #389092)
Cod sursa(job #389092)
var f:text;
a:array[1..500100] of longint;
n,i:longint;
procedure quick(bal,jobb:longint);
var koz,b,j,c:longint;
begin
if bal<jobb then begin
koz:=bal+((jobb-bal) div 2);
b:=bal;
j:=jobb;
while b<j do begin
b:=bal;
j:=jobb;
while (b<koz) and (a[b]<=a[koz]) do inc(b);
while (koz<j) and (a[j]>=a[koz]) do dec(j);
if b<j then begin
c:=a[b];
a[b]:=a[j];
a[j]:=c;
end;
end;
quick(bal,koz-1);
quick(koz+1,jobb);
end;
end;
begin
assign(f,'algsort.in');
reset(f);
readln(f,n);
for i:=1 to n do read(f,a[i]);
close(f);
quick(1,n);
assign(f,'algsort.out');
rewrite(f);
for i:=1 to n do write(f,a[i],' ');
close(f);
end.