Cod sursa(job #260338)

Utilizator petrePajarcu Alexandru-Petrisor petre Data 16 februarie 2009 22:23:45
Problema Sortare prin comparare Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.65 kb
var a:array[1..500000] of longint;
n,i,j:longint;

procedure Sort(l, r: longint);
var
  i, j, x, y: longint;
begin
  i := l; j := r; x := a[(l+r) DIV 2];
  repeat
    while a[i] < x do i := i + 1;
    while x < a[j] do j := j - 1;
    if i <= j then
    begin
      y := a[i]; a[i] := a[j]; a[j] := y;
      i := i + 1; j := j - 1;
    end;
  until i > j;
  if l < j then Sort(l, j);
  if i < r then Sort(i, r);
end;
begin
assign(input,'algsort.in');
assign(output,'algsort.out');
reset(input);
rewrite(output);
read(N);
for i:=1 to n do
    read(a[i]);
sort(1,N);
for i:=1 to n do
    write(a[i],' ');
close(input);
close(output);
end.