unit Un_list1;

interface
 uses Un_company;
 type TList=^TNodeL;
      TNodeL=record
              Company:TCompany;
              next:TList
             end;
                procedure Init (var L:TList);
                function Empty (L:TList):boolean;
                procedure Printll(L:TList);
                procedure Clear (var L:TList);
                function Found_before (var L:TList;namecompany:string):TList;
                procedure DeleteLL  (var L:TList);
                //function createLL (file_name:string;var L:TList):string;

implementation
  procedure Init (var L:TList);
  begin
    new(L);
    L^.next:=nil
  end;

  function Empty (L:TList):boolean;
  begin
    result:=L^.next=nil
  end;

  function Found_before (var L:TList;namecompany:string):TList; //поиск компании по наименованию (адрес предыдущего элемента)
  var p:TList;
  begin
    p:=L;
    while (p^.next <> nil) and  (P^.next^.company.comparecompany(namecompany)<0) do
    p := p^.next;
    result:=p
  end;

  procedure DeleteLL (var L:TList);
  var P:TList;
  begin
    p:=L^.next;
    L^.next:=p^.next;
    p^.Company.Destroy;
    Dispose(p)
  end;

  procedure Printll (L:TList);
  var p:TList;
  begin
    p:=L^.next;
    while p<>nil do
     begin
       p^.company.Print;
       p:=p^.next
     end
  end;

  procedure Clear (var L:TList);
  var p:TList;
  begin
    // удаление элементов списка
    while not Empty(L) do
     DeleteLL(L);
    // удаление заглавного звена
    Dispose(L)
  end;

end.
