unit Unit2;

interface
uses stdctrls, SysUtils;

type
TInf=integer;
PSel=^Sel;
Sel=Record
inf:TInf;
A:PSel;
end;

TList=Class(TObject)
sp1,spk,sp:PSel;
nm_zap:integer;
Constructor Create;
Procedure Addk(inf:Tinf);
Procedure Add1(inf:Tinf);
Procedure Readsp1(var Inf:Tinf);
Procedure Readspk(var Inf:Tinf);
Procedure Print(ListB1:TListBox);
Function Ariphm2(c:word):string;
end;
implementation
Constructor TList.Create;
begin
inherited create;
sp1:=nil;
spk:=nil;
end;

Procedure TList.Addk(inf:Tinf);
begin
if spk=Nil then
begin
New(spk);
spk^.A:=Nil;
spk^.Inf:=inf;
sp1:=spk;
end
else
begin
New(spk^.A);
spk:=spk^.A;
spk^.Inf:=Inf;
spk^.A:=Nil;
end;

end;

Procedure TList.Add1(inf:Tinf);
begin
if sp1=nil then
begin
New(sp1);
spk:=sp1;
sp^.inf:=inf;
sp1^.A:=nil;
end;
New(sp);
Sp^.inf:=inf;
Sp^.A:=Sp1;
Sp1:=Sp;
end;

Procedure TList.Readsp1(var Inf:Tinf);
begin
if sp1<>Nil then
begin
Inf:=sp1^.Inf;
sp:=sp1;
sp1:=sp1^.A;
if sp1=Nil then spk:=Nil;
Dispose(sp);
end;
end;

Procedure TList.Readspk(var Inf:Tinf);
var
i:integer;
begin
if spk<>Nil then
begin
Inf:=spk.Inf;
if sp1=spk then
begin
Dispose(spk);
sp1:=Nil;
spk:=Nil
end
else
begin
sp:=sp1;
while sp^.A<>Spk do sp:=sp^.A;
Dispose(spk);
spk:=sp;
spk^.A:=Nil;
end;
end;
end;

Procedure TList.Print(ListB1:TListBox);
begin
sp:=sp1;
while sp<>nil do
begin
ListB1.Items.Add(inttostr(Sp^.inf));
sp:=sp^.A;
end;
end;



Function TList.Ariphm2(c:word):string;
var
box:PSel;
sum,i:Integer;
otv:string;
begin
box:=sp1;
i:=0; sum:=0;
if c=1 then
begin
while box<>nil do
begin
Inc(i);
sum:=sum+box.inf;
if ((box.inf mod 2) = 0) then
if otv<>'' then otv:=otv+' '+inttostr(box.inf)
else otv:=inttostr(box.inf);
box:= box.a;
end;
end;

if c=2 then
begin
otv:='';
while box<>nil do
begin
Inc(i);
sum:=sum+box.inf;
if ((box.inf mod 2) <> 0) then
if otv<>'' then otv:=otv+' '+inttostr(box.inf)
else otv:=inttostr(box.inf);
box:= box.a;
end;
end;
Result:=otv;
end;

end.
Соседние файлы в папке чётн,нечётн, добавление эелемента