![]() |
|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
![]() Виртуализация элем.множества
вставка элемента удаление элемента очистка множества удаление тз 1 мн.элемента др множества определение кол-ва элемента нахождение значения max элемента Код:
Mn=set of Char; TMnVo=class private { Private declarations } fa:mn; public { Public declarations } constructor create; procedure Clear; procedure Insert(Dig: char); procedure Delete(Dig: Char); function Exist(Dig: char): Boolean; function GetCount: Integer; property Count: Integer read GetCount; procedure SetMax(Value: Char); function GetMax: Char; property Max: Char read GetMax write SetMax; procedure Exclude(G:Tmnvo); end; var Form1: TForm1; implementation var first,second,max:TMnVo; {$R *.dfm} constructor TMnVo.Create; begin fA:=[]; end; procedure Tmnvo.Clear; begin fA:=[]; end; function TMnVo.Exist(dig:char):Boolean; begin result:=dig in Fa; end; procedure TMnVo.Insert(Dig:char); begin if (Dig>='0') and (Dig<='9') and not(exist(dig)) then fA:=fA+[dig]; end; procedure TmnVo.Delete(dig:Char); begin if exist(dig) then fa:=fa-[dig] end; function TMnVo.GetCount:Integer; var i:Char; s:integer; begin s:=0; for i:='0' to '9' do if exist(i) then inc(s); result:=s end; function TmnVo.GetMax:Char; var i:Char; begin result:=#0; for i:='9' downto '0' do if exist(i) then begin result:=i; break end; end; procedure TMnVo.SetMax(Value:Char); var i:Char; begin Insert(value); for i:='9' downto value do if (exist(i)) and (i<>value) then Delete(i); end; procedure TMnVo.Exclude(g:TMnVo); var i:Char; begin for i:='0' to '9' do if self.exist(i) and g.exist(i) then self.Delete(i) end; procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char); begin if not (Key in ['0'..'9',#8]) then key:=#0; end; procedure TForm1.Button1Click(Sender: TObject); begin if cbb1.ItemIndex=0 then begin first.create; if (edt1.text<>'') and (Length(edt1.Text)=1) then first.Insert(edt1.text[1]); end; end; Последний раз редактировалось Admin, 05.12.2011 в 15:26. |