program lists2;


uses linkedList in 'linkedList.pas';
const SIZE = 10000;
var NUM: cardinal;
    code, i, j, k: integer;
    l1,l2,l3: TLinkedList;
begin
  NUM:=1;
  if ParamCount=1 then Val(ParamStr(1),NUM,code);

  for i:=1 to NUM do begin
    l1:=TLinkedList.Create;
    l2:=TLinkedList.Create;
    l3:=TLinkedList.Create;

    for j:=1 to SIZE do
      l1.addTail(j);

    if l1.getFirst(j) then
      repeat
        l2.addTail(j);
      until not l1.getNext(j);

    for j:=1 to SIZE do
      l3.addTail(l2.removeFront);

    for j:=1 to SIZE do
      l2.addTail(l3.removeTail);

    l1.reverse;

    l1.getFirst(j);
    if j<>SIZE then begin
      writeln('l1 has invalid first element'); exit;
    end;

    if (l1.Count<>SIZE)or(l1.Count<>l2.Count) then begin
      writeln('sizes don''t match'); exit;
    end;
    l1.getFirst(j); l2.getFirst(k);
    repeat
      if j<>k then begin
        writeln('l1 and l2 not equal'); exit;
      end;
    until not(l1.getNext(j) and l2.getNext(k));

    writeln(l1.count);

    l1.Destroy; l2.Destroy; l3.Destroy;
  end;
end.