ну собственно нужно реализовать операции работы со стеком на основе:
1) массива
2) динамической структуры
program stacktest;
const maxn=100;
type TElem = integer;
TElements = array [1..maxn] of TElem;
TStack = record
Elements:Telements;
Top:integer;
end;
procedure Stack_init (var s:Tstack);
begin
S.top:=0;
end;
function Stack_IsEmpty (s:Tstack):boolean;
begin
Stack_Isempty:=(s.top=0)
end;
Procedure Stack_push (var s:Tstack; E:Telem);
const errorcode = 225;
begin
with s do
if top <maxn
then
begin
top:=top+1;
Elements[top]:=E;
end
Else
begin
Writeln('perepol stek');
Halt (errorcode)
end
end;
function Stack_push_func (var s:Tstack; E:Telem):boolean;
begin
with s do
if top<maxn
then
begin
top:=top+1;
elements[top]:=e;
stack_push_func:=true
end
else
stack_push_func:=false
end;
function Stack_IsEmpty (s:Tstack):Telem;
Const ErrorCode = 255;
begin
if stack_isempty (s)
then
begin
writeln('izvlech el iz steka');
halt (errorCode)
end
else
with s do
begin
stack_pop:=Elements[top];
top:=top-1
end
end;
begin
Cost maxN=100;
Stack_init (stack);
writeln (stack_isempty = stack_isempty(stack));
write('vvedite 1 el ');
readln(e);
stack_push(stack.e);
while not stack_isempty(stack) do
writeln(stack_pop(stack));
writeln('vvedite enter');
readln;
end.
program stacktest;
const
maxn=100;
type
TElem = integer;
TElements = array [1..maxn] of TElem;
TStack = record
Elements:Telements;
Top:integer;
end;
procedure Stack_init(var s: TStack);
begin
S.top:=0;
end;
function Stack_IsEmpty(s: TStack):boolean;
begin
Stack_Isempty:=(s.top=0)
end;
Procedure Stack_push(var s: TStack; E:TElem);
const
errorcode = 225;
begin
with s do
if top<maxn then begin
top:=top+1;
Elements[top]:=E;
end
Else begin
Writeln('perepol stek');
Halt (errorcode)
end
end;
function Stack_push_func(var s: TStack; E: TElem):boolean;
begin
with s do if top<maxn then begin
top:=top+1;
elements[top]:=e;
stack_push_func:=true
end
else stack_push_func:=false
end;
function Stack_pop(var s:TStack):TElem;
Const
ErrorCode = 255;
begin
if stack_isempty(s) then begin
writeln('izvlech el iz steka');
halt (errorCode)
end
else with s do begin
stack_pop:=Elements[top];
top:=top-1
end
end;
var
Stack: TStack;
e: TElem;
begin
Stack_init (stack);
write('vvedite 1 el ');
readln(e);
stack_push(stack,e);
while not stack_isempty(stack) do writeln(stack_pop(stack));
writeln('vvedite enter');
readln;
end.
Интересный ход!Вот например зачем:
type TElem = integer;?