Pagini recente » Cod sursa (job #239425) | Cod sursa (job #3150763) | Cod sursa (job #2004445) | Cod sursa (job #1126075) | Cod sursa (job #1198900)
type tabel=array[1..1000000]of longint;
var t,a:tabel;
n,i: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];k:=k+1;i:=i+1;end
else begin a[k]:=t[j];k:=k+1;j:=j+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,'alsort.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.