uses
  dbllist, dos;

const
  n = 10000;
var
  a: array [1..n] of integer;
  l: list;
  p: pnode;
  i, j, t: integer;
  f: text;

procedure createtest;
begin
  assign(f, 'test.in');
  rewrite(f);
  randomize;
  for i := 1 to n do
    writeln(f, random(MaxInt));
  close(f);
end;

procedure swap(var x, y: integer);
begin
  t := x;
  x := y;
  y := t;
end;

procedure sorta;
begin
  assign(f, 'test.in');
  reset(f);
  for i := 1 to n do
  begin
    readln(f, a[i]);
    for j := i - 1 downto 1 do
      if a[j] > a[j+1] then
        swap(a[j], a[j+1])
      else
        break;
  end;
  close(f);

  assign(f, 'testa.out');
  rewrite(f);
  for i := 1 to n do
    writeln(f, a[i]);
  close(f);
end;

procedure sortb;
begin
  init(l);
  assign(f, 'test.in');
  reset(f);
  for i := 1 to n do
  begin
    readln(f, j);
    p := l.first;
    while (p <> nil) and (p^.key < j) do
      p := p^.next;
    insertbefore(l, p, j);
  end;
  close(f);

  assign(f, 'testb.out');
  rewrite(f);
  p := l.first;
  while p <> nil do
  begin
    writeln(f, p^.key);
    p := p^.next;
  end;

  close(f);
end;

var
  tt: longint;
  time: longint absolute $40:$6C;

begin
  createtest;
  writeln;
  tt := time;
  sorta;
  writeln('with array: time: ', (time - tt) / 18.2:0:2, 'seconds');
  tt := time;
  sortb;
  writeln('with linked-list: time: ', (time - tt) / 18.2:0:2, 'seconds');
end.
