Ada Integer Stack Pkg
-- -- Linked-list based stack package. -- package IntStackPkg is -- This declares that IntStack is a type, but the contents of the type -- are private, and are invisible to clients of the package. The -- modifier limited additionally forbids the client to copy or compare -- stacks. type IntStack is limited private; -- All the public stack operations. procedure Push(S: in out IntStack; I: Integer); procedure Pop(S: in out IntStack; I: out Integer); function Top(S: IntStack) return Integer; function IsEmpty(S: IntStack) return Boolean; procedure Clear(S: in out IntStack); private -- The items here cannot be accessed by clients of the package. type StackNode; -- There is a node type. type IntStack is access all StackNode; -- Stack is ptr to a list head type NodePtr is access all StackNode; -- Other node pointers. type StackNode is record -- Nodes are like this. Data: Integer; -- Content. Next: NodePtr; -- Link to next node. end record; end IntStackPkg; -- -- Note: We have no direct way to initialize Stacks when declared. We -- depend on the behavior of Ada that pointers are always initialized to -- null. --