Pagini recente » Cod sursa (job #697833) | Cod sursa (job #1910648) | Cod sursa (job #3214515) | Cod sursa (job #651876) | Cod sursa (job #282049)
Cod sursa(job #282049)
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.