unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; type ElementType=Char; Pointer=^StackNode; StackNode=record Element:ElementType; Next:Pointer; end; TStack=class constructor Create; destructor Destroy; function IsEmpty:Boolean; procedure Push(Item:ElementType); procedure Pop(var Item:ElementType); // private Top:Pointer; end; var Form1: TForm1; implementation {$R *.dfm} { TStack } constructor TStack.Create; begin Top:=nil; end; destructor TStack.Destroy; var P:Pointer; begin while Top <>nil do begin P:=Top; Top:=Top^.Next; dispose(P); end; end; function TStack.IsEmpty: Boolean; begin IsEmpty:=Top=nil; end; procedure TStack.Pop(var Item: ElementType); var P:Pointer; begin if IsEmpty then else begin Item:=Top^.Element; P:=Top; Top:=Top^.Next; dispose(P); end; end; procedure TStack.Push(Item: ElementType); var P:Pointer; begin new(P); P^.Element:=Item; P^.Next:=Top; Top:=P; end; procedure TForm1.Button1Click(Sender: TObject); var aStack: TStack; a,b,c: Char; str: string; begin a := '1'; b := '2'; c := '3'; aStack := TStack.Create; try aStack.Push(a); aStack.Push(b); aStack.Push(c); ShowMessage(a+b+c); // aStack.Pop(a); aStack.Pop(b); aStack.Pop(c); ShowMessage(a+b+c); finally aStack.Free; end; end; end.