Stack栈的使用
要引用:Contnrs
-----------------------
procedure TForm1.Button1Click(Sender: TObject);
var a:TStack;s1,s2:string;
b:^string;
begin
s1:='Hello';
s2:='Word';
a:=TStack.Create;
a.Push(@s1);
a.Push(@s2);
b:=a.Peek;
ShowMessage(b^);
//Stack里面只能放一种数据类型,上面是放string
end;
procedure TForm1.Button2Click(Sender: TObject);
var
a:TStack;
b,b1:Integer;
bb:^Integer;
begin
b:=1;
b1:=2;
a:=TStack.Create;
a.Push(@b);
a.Push(@b1);
bb:=a.Peek;
ShowMessage(IntToStr(bb^));
//Stack里面放的是实数
end;
---------------ObjectStack-------------------------------------
procedure TForm1.Button4Click(Sender: TObject);
var
a:TObjectStack;
s:string;
i:Integer;
begin
a:=TObjectStack.Create;
s:='Hello Word';
i:=1;
a.Push(@s);
a.Push(@i);
//ObjectStack可以装混合数据
end;
-------------------------------------------------------