Delphi队列和栈
2021-04-02 02:25
标签:lse 数据 forms vat tab creat obj charset integer ----------------D7 一般把栈叫堆栈;数据结构上的堆和栈是两个不同的东西; ------------------ --------------Unit {Queue(队列),先进先出;Stack(堆栈),后进先出} interface uses type var implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); end; procedure TForm1.FormCreate(Sender: TObject); procedure TForm1.Button2Click(Sender: TObject); ---------------Unit- ----------------Form object Form1: TForm1 ------------------Form--- Delphi队列和栈 标签:lse 数据 forms vat tab creat obj charset integer 原文地址:https://www.cnblogs.com/dmqhjp/p/14597259.html
unit Unit1;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Contnrs ; //,ExtCtrls
PMyrecord = ^TMyrecord;
TMyrecord = record
RCode: String;
end;
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
Myqueue:TQueue;
Mystack:TStack;
PRe: PMyrecord;
{ Private declarations }
public
{ Public declarations }
end;
Form1: TForm1;
var
i: Integer;
begin
try
for i := 0 to 9 do
begin
New(PRe);
PRe.RCode:= IntToStr(i);
Myqueue.Push(PRe);
end;
while Myqueue.Count > 0 do
begin
PRe:= Myqueue.Pop;
memo1.Lines.Add(PRe.RCode);
Dispose(PRe);
end;
except
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FreeAndNil(Myqueue);
FreeAndNil(Mystack);
end;
begin
Myqueue:= TQueue.Create;
Mystack:= TStack.Create;
end;
var
i: Integer;
begin
try
for i := 0 to 9 do
begin
New(PRe);
PRe.RCode:= IntToStr(i);
Mystack.Push(PRe);
end;
while Mystack.Count > 0 do
begin
PRe:=Mystack.Pop;
Memo1.Lines.Add(PRe.RCode);
Dispose(PRe);
end;
except
end;
end;
end.
Left = 840
Top = 634
Width = 305
Height = 311
Caption = ‘Form1‘
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = ‘MS Sans Serif‘
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 192
Top = 24
Width = 75
Height = 25
Caption = ‘B1_queue‘
TabOrder = 0
OnClick = Button1Click
end
object Memo1: TMemo
Left = 0
Top = 0
Width = 185
Height = 273
Align = alLeft
ImeName = ‘中文(简体) - 搜狗拼音输入法‘
ScrollBars = ssBoth
TabOrder = 1
end
object Button2: TButton
Left = 192
Top = 176
Width = 75
Height = 25
Caption = ‘B2_stack‘
TabOrder = 2
OnClick = Button2Click
end
end
上一篇:C# While 超时设置