home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 31 - Program 7
- generic
- type ITEM is private;
- package GenStack is
-
- procedure Push(In_Item : in ITEM); -- In_Item is added to the
- -- stack if there is room.
-
- procedure Pop(Out_Item : out ITEM); -- Out_Item is removed from
- -- stack and returned if a
- -- character is on stack.
- -- else a blank is returned
-
- function Is_Empty return BOOLEAN; -- TRUE if stack is empty
-
- function Is_Full return BOOLEAN; -- TRUE if stack is full
-
- function Current_Stack_Size return INTEGER;
-
- procedure Clear_Stack; -- Reset the stack to empty
-
- end GenStack;
-
-
-
-
-
- package body GenStack is
-
- Maximum_Size : constant := 25;
- type ITEM_ARRAY is array(1..Maximum_Size) of ITEM;
- Stack_List : ITEM_ARRAY; -- The stack itself, purposely
- -- defined very small.
- Top_Of_Stack : INTEGER := 0; -- This will always point to
- -- the top entry on the stack.
-
- procedure Push(In_Item : in ITEM) is
- begin
- if not Is_Full then
- Top_Of_Stack := Top_Of_Stack + 1;
- Stack_List(Top_Of_Stack) := In_Item;
- end if;
- end Push;
-
-
- procedure Pop(Out_Item : out ITEM) is
- begin
- if Is_Empty then
- null; -- Nothing to return
- else
- Out_Item := Stack_List(Top_Of_Stack);
- Top_Of_Stack := Top_Of_Stack - 1;
- end if;
- end Pop;
-
-
- function Is_Empty return BOOLEAN is
- begin
- return Top_Of_Stack = 0;
- end Is_Empty;
-
-
- function Is_Full return BOOLEAN is
- begin
- return Top_Of_Stack = Maximum_Size;
- end Is_Full;
-
-
- function Current_Stack_Size return INTEGER is
- begin
- return Top_Of_Stack;
- end Current_Stack_Size;
-
-
- procedure Clear_Stack is
- begin
- Top_Of_Stack := 0;
- end Clear_Stack;
-
- end GenStack;
-
-