Pagini recente » Cod sursa (job #390533) | Cod sursa (job #1968404) | Cod sursa (job #521651) | Cod sursa (job #2631590) | Cod sursa (job #286404)
Cod sursa(job #286404)
type vector=array[1..500000] of longint;
var a:vector;
n,ii,m:longint;
f,g:text;
procedure Sortare(s,d:longint);
VAR i,j,l1,l2:longint;
x,z,w:longint;
begin
i:=s; j:=d; x:=a[(s+d) div 2]; l1:=1; l2:=0 ;
repeat
while a[i]<x do i:=i+1;
while a[j]>x do j:=j-1;
if i<=j then begin
w:=a[i]; a[i]:=a[j]; a[j]:=w;
i:=i+1; j:=j-1
end
{ if a[i]>a[j] then begin
w:=a[i]; a[i]:=a[j]; a[j]:=w;
z:=l1; l1:=-l2; l2:=-z; i:=i+l1; j:=j+l2;
end else
begin i:=i+l1; j:=j+l2; end; }
until i>j;
if s<j then Sortare(s,j);
if d>i then Sortare(i,d);
end;
begin
assign(f,'algsort.in'); assign(g,'algsort.out');
reset(f); rewrite(g);
readln(f,n);
for ii:=1 to n do read(f,a[ii]);
m:=1;
Sortare(m,n);
for ii:=1 to n do
write(g,a[ii],' ');
close(f); close(g);
end.