Pagini recente » Cod sursa (job #846690) | Cod sursa (job #3220760) | Cod sursa (job #2275494) | Cod sursa (job #1805425) | Cod sursa (job #294700)
Cod sursa(job #294700)
var a:array[1..500000] of longint;
f,g:Text;
aux:longint;
n,i:longint;
procedure sort(l,r:longint);
var i,j:longint;
pivot:longint;
begin
i:=l; j:=r; pivot:=a[random(r-l)+l];
repeat
while a[i]<pivot do i:=i+1;
while pivot<a[j] do j:=j-1;
if i<=j then begin
aux:=a[i];
a[i]:=a[j];
a[j]:=aux;
i:=i+1; j:=j-1;
end;
until i>j;
if i<r then sort(i,r);
if l<j then sort(l,j);
end;
begin
randomize;
assign(f,'algsort.in'); reset(f);
assign(g,'algsort.out'); rewrite(g);
read(f,n);
for i:=1 to n do read(f,a[i]);
sort(1,n);
for i:=1 to n do write(g,a[i],' ');
close(f); close(g);
end.