TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

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

Print Reply
Sender:
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
X-To:
Tsehay Scroggins <[log in to unmask]>
Date:
Mon, 2 Nov 1998 08:10:21 -0600
Reply-To:
John McCormick <[log in to unmask]>
Subject:
From:
John McCormick <[log in to unmask]>
In-Reply-To:
Content-Type:
TEXT/PLAIN; charset=US-ASCII
MIME-Version:
1.0
Parts/Attachments:
TEXT/PLAIN (173 lines)
Hmmm,

This looks like a request for Team Ada folks to answer a slightly expanded
version of question #22 on page 301 of the textbook _Ada Plus Data
Structures: An Object-Based Approach_.  Have a look at the material in the
preceeding 30 pages and you should then be able to answer the question.

John


On Sun, 1 Nov 1998, Tsehay Scroggins wrote:

> 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
>


-------------------------------------------------------
John W. McCormick                [log in to unmask]
Computer Science Department      [log in to unmask]
University of Northern Iowa      voice  (319) 273-2618
Cedar Falls, IA  50614-0507      fax    (319) 273-7123

ATOM RSS1 RSS2