![Старый](images/statusicon/post_old.gif)
03.03.2010, 21:58
|
Прохожий
|
|
Регистрация: 29.12.2008
Сообщения: 15
Репутация: 10
|
|
Помогите пожалуйста доработать программу. Как сделать чтобы в Мемо выводился стэк из
Помогите пожалуйста доработать программу. Как сделать чтобы в Мемо выводился стэк из 5 строк и длиной 10 символов ?
Код:
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;
S:TStack;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
S:=TStack.Create;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.Lines.Add(pansichar(S));
end;
end.
unit Unit2;
interface
uses SysUtils, Dialogs;
const StackEmpty=nil;
type
T=integer;
TStackEl=^StackEl;
StackEl=record
el:T;
prev:TStackEl;
end;
TStack=class
private
StackTop:TStackEl;
public
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.
Последний раз редактировалось Nostalgia, 03.03.2010 в 22:28.
|