Pagini recente » Cod sursa (job #15421) | Cod sursa (job #855027) | Cod sursa (job #333271) | Cod sursa (job #69701) | Cod sursa (job #1199103)
type tabel=array[1..500000]of longint;
var t,a:tabel;
n,i,j:longint;
procedure combina(st,m,dr:longint);
var i,j,k:longint;
begin
i:=st;
j:=m+1;
k:=1;
while (i<=m)and(j<=dr)do
begin
if t[i]<t[j] then begin a[k]:=t[i];i:=i+1;k:=k+1;end
else begin a[k]:=t[j];j:=j+1;k:=k+1;end
end;
while i<=m do begin a[k]:=t[i];i:=i+1;k:=k+1;end;
while j<=dr do begin a[k]:=t[j];j:=j+1;k:=k+1;end;
k:=st;
for i:=1 to dr-st+1 do
begin
t[k]:=a[i];
k:=k+1;
end;
end;
procedure mergesort(st,dr:longint);
var m:longint;
begin
if st<dr then
begin
m:=(st+dr)div 2;
mergesort(st,m);
mergesort(m+1,dr);
combina(st,m,dr);
end;
end;
begin
assign(input,'algsort.in');
reset(input);
readln(n);
for i:=1 to n do read(t[i]);
close(input);
mergesort(1,n) ;
assign(output,'algsort.out');
rewrite(output);
for i:=1 to n do write(t[i],' ');
close(output);
end.