
05.03.2010, 19:33
|
Прохожий
|
|
Регистрация: 29.12.2008
Сообщения: 15
Репутация: 10
|
|
всё исправила. в мемо не выводятся строки(( почему ? подскажите пожалуйста
Код:
Цитата:
Сообщение от lmikle
вообще, примерно так:
Код:
var
P : TStackEl;
begin
memo1.lines.clear;
P := S.StackTop;
while P <> Nil do
begin
memo1.lines.add(P.el);
P := P.prev;
end;
end;
ЗЫ. Использовал твое описание.
|
Цитата:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Unit2;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MySTack:TStack;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
MyStack:=TStack.Create;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
P : TStackEl;
begin
memo1.lines.clear;
P := MyStack.StackTop;
while P <> Nil do
begin
memo1.lines.add(P.el);
P := P.prev;
end;
end;
end.
unit Unit2;
interface
uses SysUtils, Dialogs;
const
StackEmpty=nil;
type
T=string[10];
TStackEl=^StackEl;
StackEl=record
el:T;
prev:TStackEl;
end;
TStack=class
public
StackTop:TStackEl;
Constructor Create; //конструктор
function EmptyStack:boolean; // проверка, не пустой ли стэк
procedure AddToStack(elem:T);
procedure DelFromStack;
function LastOfStack:T;
end;
implementation
Constructor TStack.Create;
begin
Inherited Create;
end;
function TStack.EmptyStack;
begin
EmptyStack:=StackTop=StackEmpty;
end;
procedure TStack.AddToStack;
var
tmp:TStackel;
begin
new(tmp);
tmp^.el:=elem;
tmp^.prev:=StackTop;
StackTop:=tmp;
end;
procedure TStack.DelFromStack;
var
help:TStackEl;
begin
if StackTop<>StackEmpty then
begin
help:=StackTop;
Stacktop:=StackTop^.prev;
dispose(help);
end
else
showmessage('error stack pust');
end;
function TSTack.LastOfStack;
begin
if StackTop<>StackEmpty then
result:=STackTop^.el
else showmessage('error1 stack pust');
end;
end.
|
|