brackelib_0.0.2_e08b6041/src/brackelib-stacks.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
with Ada.Containers.Doubly_Linked_Lists;
use Ada.Containers;

generic
  type T is private;
package Brackelib.Stacks is
--  @summary
--  Implementation of the stack abstract data type

   type Stack is limited private;

   procedure Push (Self : in out Stack; Item : T);
   --  Adds an item to the top of the stack making it the top item.
   --  @param Self The stack
   --  @param Item The item to be added

   function Pop (Self : in out Stack) return T;
   --  Removes the top item off the stack and returns it.
   --  @param Self The stack
   --  @return Item The top item is returned
   --  @exception Stack_Empty Raised if the stack is empty and thus no item can be returned.

   function Top (Self : in Stack) return T;
   --  Returns the top item without removing it from the stack.
   --  @param Self The stack
   --  @return Item The top item is returned
   --  @exception Stack_Empty Raised if the stack is empty and thus no item can be returned.

   function Size (Self : Stack) return Natural;
   --  Returns the number of items in the stack.
   --  @param Self The stack
   --  @return Count Number of items in the stack

   function Is_Empty (Self : Stack) return Boolean;
   --  Returns whether the stack is empty.
   --  @param Self The stack
   --  @return True If the stack is empty

   procedure Clear (Self : in out Stack);
   --  Removes all items from the stack.
   --  @param Self The stack


   Stack_Empty : Exception;

private

   package Stack_Container is new Doubly_Linked_Lists(T);
   use Stack_Container;

   type Stack is record
      Container: List;
   end record;

end Brackelib.Stacks;