home *** CD-ROM | disk | FTP | other *** search
- -- ++
- -- A simple stack for integers.
- -- --
-
- package body Stack is
-
- procedure Push ( The_Stack : in out Stack; Value : in Integer ) is
- begin
- if The_Stack.Top = The_Stack.Max then
- raise Overflow;
- end if;
- The_Stack.Top := The_Stack.Top + 1;
- The_Stack.S ( The_Stack.Top ) := Value;
- end Push;
-
- procedure Pop ( The_Stack : in out Stack; Value : out Integer ) is
- begin
- if The_Stack.Top = 0 then
- raise Underflow;
- end if;
- Value := The_Stack.S ( The_Stack.Top );
- The_Stack.Top := The_Stack.Top - 1;
- end Pop;
-
- function "=" ( The_Stack : in Stack; A_Stack : in Stack ) return Boolean is
- begin
- if The_Stack.Top /= A_Stack.Top then
- return False;
- elsif The_Stack.Max < A_Stack.Top or else A_Stack.Max < The_Stack.Top then
- return False;
- else
- return The_Stack.S ( 1 .. The_Stack.Top ) = A_Stack.S ( 1 .. A_Stack.Top );
- end if;
- return True;
- end "=";
-
- function Empty ( The_Stack : in Stack ) return Boolean is
- begin
- return The_Stack.Top = 0;
- end Empty;
-
- function Full ( The_Stack : in Stack ) return Boolean is
- begin
- return The_Stack.Top = The_Stack.Max;
- end Full;
-
- end Stack;