Mai intai trebuie sa te autentifici.
Cod sursa(job #285849)
Utilizator | Data | 23 martie 2009 05:44:00 | |
---|---|---|---|
Problema | Sortare prin comparare | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.79 kb |
type vector=array[1..500000] of longint;
var a:vector;
n,i,m:longint;
f,g:text;
procedure Sortare(s,d:longint);
VAR i,j:longint;
x,w:longint;
begin
i:=s; j:=d; x:=(s+d) div 2;
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
until i>j;
if s<j then Sortare(s,j);
if d>i then Sortare(i,d);
end; {Sortare}
begin
assign(f,'algsort.in'); assign(g,'algsort.out');
reset(f); rewrite(g);
readln(f,n);
for i:=1 to n do read(a[i]);
m:=1;
Sortare(m,N);
for i:=1 to n do
write(g,a[i],' ');
close(f); close(g);
end.