home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LANGUAGE / ADA / LOVELACE / genestac.ads < prev    next >
Text File  |  1996-10-01  |  2KB  |  46 lines

  1.   with Ada.Finalization; use Ada.Finalization;
  2.  
  3.   generic
  4.     type Item is private;  -- This is the data type to be stacked.
  5.  
  6.   package Generic_Stack is
  7.     -- This implements a simple generic stack of Items.
  8.     -- (C) 1996 David A. Wheeler.
  9.  
  10.     type Stack is new Controlled with private;
  11.      -- Stack type. Assignment copies the contents of one Stack into another,
  12.      -- and might copy each Item in the Stack.
  13.      -- You can inherit from Stack and overload its controlled operations.
  14.     type Stack_Access is access all Stack'Class;
  15.      -- standard access type.
  16.     function "="(Left : in Stack; Right : in Stack) return Boolean;
  17.      -- Stacks are equal if lengths equal and each item in order is equal.
  18.     procedure Swap(Left : in out Stack; Right : in out Stack);
  19.      -- Swap the contents of the two stacks.
  20.  
  21.     procedure Push(S : in out Stack; I : in  Item);
  22.     procedure Pop (S : in out Stack; I : out Item);
  23.      -- Pop raises Constraint_Error if Is_Empty(Stack).
  24.     procedure Top (S : in out Stack; I : out Item);
  25.      -- Top copies, but does not Pop, the topmost element. 
  26.      -- Top raises Constraint_Error if Is_Empty(Stack).
  27.     procedure Empty(S : in out Stack); -- Empties the given Stack
  28.  
  29.     function Is_Empty(S : in Stack) return Boolean; -- True if Empty.
  30.     function Length(S : in Stack) return Natural; -- returns 0 if Empty
  31.  
  32.     -- Permission is granted to use this package in any way you wish under
  33.     -- the condition that the author (David A. Wheeler) is given credit.
  34.     -- NO WARRANTIES, EITHER EXPRESS OR IMPLIED, APPLY.
  35.  
  36.   private 
  37.     type Stack_Node;
  38.     type Stack_Node_Access is access Stack_Node;
  39.     type Stack is new Controlled with record
  40.           Start : Stack_Node_Access;
  41.         end record;
  42.     procedure Adjust(Object : in out Stack);
  43.     procedure Finalize(Object : in out Stack);
  44.   end Generic_Stack;
  45.  
  46.