Cod sursa(job #1413353)

Utilizator RaduhhRadu Flocea Raduhh Data 1 aprilie 2015 20:28:23
Problema Sortare prin comparare Scor 20
Compilator fpc Status done
Runda Arhiva educationala Marime 0.59 kb
var n,i:longint;
    t:array[1..500000] of qword;
procedure qsort(l,r:qword);
var i,y,k,j:qword;
begin
 i:=l;
 j:=r;
 k:=t[(l+r) div 2];
 while t[i]<k do i:=i+1;
 while t[j]>k do j:=j-1;
 if i<=j then
  begin
   y:=t[i]; t[i]:=t[j]; t[j]:=y;
   i:=i+1; j:=j-1;
  end;
 if l<j then qsort(l,j);
 if i<r then qsort(i,r);
end;
begin
 assign(input,'algsort.in');
 reset(input);
 readln(n);
 for i:=1 to n do
 read(t[i]);
 qsort(1,n);
 close(input);


 assign(output,'algsort.out');
 rewrite(output);
 for i:=1 to n-1 do
 write(t[i],' ');
 write(t[n]);
 close(output);
end.