RosettaCodeData/Task/Stack/Elisa/stack-1.elisa

22 lines
901 B
Plaintext

component GenericStack ( Stack, Element );
type Stack;
Stack (MaxSize = integer) -> Stack;
Empty ( Stack ) -> boolean;
Full ( Stack ) -> boolean;
Push ( Stack, Element) -> nothing;
Pull ( Stack ) -> Element;
begin
Stack(MaxSize) =
Stack:[ MaxSize; index:=0; area=array (Element, MaxSize) ];
Empty( stack ) = (stack.index <= 0);
Full ( stack ) = (stack.index >= stack.MaxSize);
Push ( stack, element ) =
[ exception (Full (stack), "Stack Overflow");
stack.index:=stack.index + 1;
stack.area[stack.index]:=element ];
Pull ( stack ) =
[ exception (Empty (stack), "Stack Underflow");
stack.index:=stack.index - 1;
stack.area[stack.index + 1] ];
end component GenericStack;