unit Un_network;

interface
  uses
  Un_company, Un_Abonent, Un_list1;
  type TNetwork=class
                public
                FName:string;
                FL:TList;
                constructor Create (namenetwork:string);
                destructor Destroy; override;
                procedure Print;
                function Add(namecompany:string;abonent:TAbonent):boolean;
                function del(namecompany:string;abonent:TAbonent):Boolean;
                end;

implementation

  constructor TNetwork.Create;
  begin
    inherited Create;
    FName:=namenetwork;
    Init(FL);
  end;

  procedure TNetwork.Print;
  begin
    Writeln(FName,':');
    Printll(FL);
  end;

  destructor TNetwork.Destroy;
  begin
    Clear(FL);
    inherited Destroy
  end;

 function TNetwork.del(namecompany:string;abonent:TAbonent):Boolean;
 var p:TList;
     numberphone:TAbonent;
 begin
    p:=Found_before(fL,namecompany);
    if(p^.next <> nil) or  (P^.next^.company.comparecompany(namecompany)>0) then result:=false
                                                                            else // компания есть,ищем абонента по номеру телефона
                                                                            begin
                                                                              result:=true;
                                                                              p^.next^.Company.Del_ab(numberphone);
                                                                            end;
 end;

 function TNetwork.Add(namecompany:string;abonent:TAbonent):boolean;
 var p,q:TList;
 begin
   p:=Found_before(fl,namecompany);
   if(p^.next = nil) or  (P^.next^.company.comparecompany(namecompany)>0) then
   begin  //такой компании нет,создаем новую компанию
     New(q);
     q^.Company:=TCompany.Create(namecompany);
     q^.next:=p^.next;
     p^.next:=q
   end;
    //по адресу компании добавляем абонента
    {p:=p^.next;
    p^.Company.Add_ab(abonent);
    if not p^.Company.found(abonent) then abonent.destroy }

 end;

end.
