TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Classic View

Use Proportional Font
Show Text Part by Default
Show All Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Tsehay Scroggins <[log in to unmask]>
Sun, 1 Nov 1998 08:24:24 PST
text/plain (153 lines)
generic -- We can create a Deque of anything

   type Element_Type is private;

package Deque is

    -- What do you get when you cross a Stack and a Queue?

    -- A DEQUE  !! ( pronounced Deck)

    -- Additions and deletions are allowed from both ends

    --
   type Deque_Type is limited private;


   Overflow: exception;
   Underflow: exception;
   -----------------------------------------------------
   procedure Clear ( Deque : in out  Deque_Type);
   -- This procedure initializes the Deque to  empty


   -----------------------------------------------------
   procedure In_Deque_Front ( Deque : in out  Deque_Type;
                              Item  : in Element_Type);

   -- This procedure adds Item to the front of the Deque
   -- Preconditions : none
   -- Postconditions: Deque is the original Deque with Item added to
   --                 front
   -- Exceptions    : Overflow is raised if there is no room in
   --                 the Deque for Item. Deque is unchanged

-----------------------------------------------------
   procedure In_Deque_Back ( Deque : in out  Deque_Type;
                             Item  : in Element_Type);

   -- This procedure adds Item to the back ( rear) of the Deque
   -- Preconditions : none
   -- Postconditions: Deque is the original Deque with Item added to
   --                 back ( rear)
   -- Exceptions    : Overflow is raised if there is no room in
   --                 the Deque for Item. Deque is unchanged

   -----------------------------------------------------

 procedure Out_Deque_Front ( Deque : in out  Deque_Type;
                             Item  :  out Element_Type);

   -- This procedure removes Item from the front of the Deque
   -- Preconditions : none
   -- Postconditions:
   --     Deque = the original Deque with the front element removed.
   --     Item  = the element that was removed from the original Deque.

   -- Exceptions    : Underflow is raised if the Deque is empty.
   --                 Deque is unchanged.

   -----------------------------------------------------
   procedure Out_Deque_Back ( Deque : in out  Deque_Type;
                             Item  :  out Element_Type);

   -- This procedure removes Item from the back (rear)of the Deque
   -- Preconditions : none
   -- Postconditions:
   --     Deque = the original Deque with the back element removed.
   --     Item  = the element that was removed from the original Deque.

   -- Exceptions    : Underflow is raised if the Deque is empty.
   --                 Deque is unchanged.


    -----------------------------------------------------
   procedure Copy ( Target : in out  Deque_Type;
                    Source : in Deque_Type);

   -- This procedure makes Target a copy of Source.
   -- Preconditions : None
   -- Postconditions: Target will contain exaclty the same entries
   --                 in the same order as Source.



    -----------------------------------------------------
   function Equal  ( Left : in Deque_Type;
                     Right : in Deque_Type) return Boolean;

   -- This function returns True when left and  Right contain the
   -- same elements in the same order and False otherwise.

   -- Preconditions : none
   -- Postconditions:
   --   Equal = (Left and Right contain the same items in the same
order)

    -----------------------------------------------------
   function Full ( Deque: in Deque_Type ) return Boolean;

   -- This function determines whether or not the Deque is full.

   -- Preconditions : none
   -- Postconditions:  Full = ( Deque is full)
   --


   -----------------------------------------------------
   function Empty ( Deque: in Deque_Type ) return Boolean;

   -- This function determines whether or not the Deque is empty.

   -- Preconditions : none
   -- Postconditions:  Full = ( Deque is empty)
   --


   -----------------------------------------------------
    function Count ( Deque: in Deque_Type ) return Natural;

   -- This function counts the number of items in the Deque.

   -- Preconditions : none
   -- Postconditions:  Count = Number of items in Deque

   -----------------------------------------------------

   private

       type Node_Type ;

       type Ptr_Type is access Node_Type;

       type Node_Type is
          record
            Info : Element_Type;
            Next : Ptr_Type;
          end record  ;

       type Deque_Type is
          record
            Front :  Ptr_Type;
            Back  : Ptr_Type;
          end record;

end Deque;


--------------------


______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

ATOM RSS1 RSS2