{$MODE OBJFPC}
{$MODESWITCH AUTODEREF}
uses
  dstrings,
  dlist_oldstyle,
  dhashfuncs;

var
  A, B: LongInt;
  List: TList;
  Data, Middle: Pointer;

function LessThan(A, B: Pointer): Boolean;
begin
  Result := LongInt(A^) < LongInt(B^);
end;

begin
  List.Init(SizeOf(LongInt));
  A := 2;
  List.Add(@A);
  A := 4;
  List.Add(@A);
  A := 6;
  Middle := List.Add(@A);
  A := 8;
  List.Add(@A);

  Data := List.Head;
  while List.Next(Data) do
    Write(LongInt(Data^), ' ');
  Writeln;

  A := 55;
  List.AddBefore(@A, Middle);
  List.Del(Middle);
  Data := List.Head;
  while List.Next(Data) do
    Write(LongInt(Data^), ' ');
  Writeln;

  List.Clear;
  A := 4; List.AddSorted(@A, @LessThan);
  A := 9; List.AddSorted(@A, @LessThan);
  A := 1; List.AddSorted(@A, @LessThan);
  A := 5; List.AddSorted(@A, @LessThan);
  A := 2; List.AddSorted(@A, @LessThan);
  A := 8; List.AddSorted(@A, @LessThan);
  A := 6; List.AddSorted(@A, @LessThan);
  A := 7; List.AddSorted(@A, @LessThan);
  A := 3; List.AddSorted(@A, @LessThan);
  Data := List.Head;
  while List.Next(Data) do
    Write(LongInt(Data^), ' ');
  Writeln;

  List.Done;
end.
