258
>Operatii in stiva statica:creare, parcurgere, adaugare, eliminare.
program stiv;
type stiva=array[0..100] of integer;
var s:stiva;
vf,n,i:integer;
st_plina,st_vida:boolean;
procedure initializare;
var i:integer;
begin
write('numarul de elemente al stivei=');readln(n);
for i:=1 to n do s[i]:=0;
vf:=0;
end;
procedure adaugare;
var e:integer;
begin
write('elementul care se adauga=');
readln(e);
if vf=n then st_plina:=true
else st_plina:=false;
if st_plina then
begin
writeln('depasire stiva');
readln;
end
else
begin
vf:=vf+1;
s[vf]:=e;
end;
end;
procedure parcurg;
var i:integer;
begin
writeln('stiva este:');
i:=vf;
while i<>0 do
begin
writeln(s[i]:5);
dec(i);
end;
readln;
end;
procedure eliminare;
var e:integer;
begin
if vf=0 then st_vida:=true
else st_vida:=false;
if st_vida then
begin
writeln('stiva vida');
readln;
end
else
begin
e:=s[vf];
dec(vf);
end;
writeln('s-a eliminat elementul ',e);
end;
BEGIN
initializare;
for i:=1 to n do adaugare;
parcurg;
END.
{PascalZone.uv.ro}