Pagini recente » Cod sursa (job #137759) | Cod sursa (job #1701878) | Cod sursa (job #136786) | Cod sursa (job #1859878) | Cod sursa (job #286391)
Cod sursa(job #286391)
type vector=array[1..50] 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:=(s+d) div 2;}l1:=1; l2:=0 ;
repeat
{while a[i]<a[x] do i:=i+1;
while a[j]>a[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-1 then Sortare(s,j-1);
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.