program heapsort; const IM = 139968; IA = 3877; IC = 29573; var LAST: integer = 42; function gen_random(n: double): double; begin LAST := (LAST * IA + IC) mod IM; result := n * LAST / IM; end; // 1:1 translation of Java-version, error if n=1 procedure sort(n: integer; var a: array of double); var rra: double; i, j, l, ir: integer; begin l:=(n shr 1)+1; ir:=n; while True do begin if l>1 then begin dec(l); rra:=a[l]; end else begin rra:=a[ir]; a[ir]:=a[1]; dec(ir); if (ir=1) then begin a[1]:=rra; exit; end; end; i:=l; j:=l shl 1; while (j<=ir) do begin if (j<ir)and(a[j]<a[j+1]) then inc(j); if (rra<a[j]) then begin a[i]:=a[j]; i:=j; inc(j,j); end else j:=ir+1; end; a[i]:=rra; end; end; var NUM, code, i: integer; ary: array of double; begin NUM:=1; if ParamCount=1 then Val(ParamStr(1),NUM,code); setLength(ary,NUM+1); ary[0]:=0.0; for i:=1 to NUM do ary[i]:=gen_random(1); sort(NUM, ary); WriteLn(ary[NUM]:10:10); end.