unit uList;
// cdmlex, реализация списков v0.2, 14.06.13
interface

type
  TList = class
    Count : Integer;
    Next, Prev, Root : TList;
    constructor Create; virtual;
    function  Add(E : TList) : TList; virtual;
    procedure Del;
    procedure Init; virtual;
    procedure Update; virtual;
    procedure Draw; virtual;
    procedure Clear;
    procedure Excl;
  end;

implementation

constructor TList.Create;
begin
  Root := Self;
  Next := Self;
  Prev := Self;
end;

function TList.Add(E : TList) : TList;
begin
  E.Root := Root;

  E.Next := Root;
  E.Prev := Root.Prev;
  Root.Prev.Next := E;
  Root.Prev := E;

  E.Init;
  Root.Count := Root.Count + 1;
  Result := E;
end;

procedure TList.Del;
begin
  if Root <> Self then
  begin
    Next.Prev := Prev;
    Prev.Next := Next;
    Root.Count := Root.Count - 1;
    Destroy;
  end;
end;

procedure TList.Draw;
begin
end;

procedure TList.Update;
begin
end;
procedure TList.Clear;
var
  TL, Tl1 : TList;
begin
  TL := Root.Next;
  while (TL <> Root) and (TL <> nil) do
  begin
    Tl1 := TL;
    TL := Tl1.Next;
    TL1.Del;
  end;

  Root := Self;
  Next := Self;
  Prev := Self;
end;

procedure TList.Excl;
begin
  if Root <> Self then
  begin
    Next.Prev := Prev;
    Prev.Next := Next;
    Root.Count := Root.Count - 1;
    Root := nil;
    Next := nil;
    Prev := nil;
  end;
end;

procedure TList.Init;
begin

end;

end.
