home *** CD-ROM | disk | FTP | other *** search
- {\magonebf 3.6 Bounded Queues (b\_queue) }
-
- An instance $Q$ of the data type $b\_queue$ is a queue (see section 2.4)
- of bounded size.
-
- \bigskip
- {\bf 1. Declaration of a bounded queue type}
-
- \decl b\_queue E
-
- introduces a new data type with name \name\ consisting all bounded queue with
- element type $E$.
-
-
- \bigskip
- {\bf 2. Creation of a bounded queue}
-
- \create Q (n)
-
- creates an instance \var\ of type \name\ that can hold up to $n$ elements.
- \var\ is initialized with the empty queue.
-
-
- \bigskip
- {\bf 3. \operations}
- \+\cleartabs & \hskip 2truecm & \hskip 4truecm &\cr
- \+\op E top {}
- { returns the front element of \var}
- \+\nop { \precond $Q$ is not empty.}
- \smallskip
- \+\op E pop {}
- { deletes and returns the front element of \var}
- \+\nop { \precond $Q$ is not empty.}
- \smallskip
- \+\op E append {E\ x}
- { appends $x$ to the rear end of \var}
- \+\nop { \precond $Q$.size()$ < n$.}
- \smallskip
- \+\op void clear {}
- { makes \var\ the empty queue.}
- \smallskip
- \+\op int size {}
- { returns the size of \var.}
- \smallskip
- \+\op bool empty {}
- { returns true if \var\ is empty, false otherwise.}
-
- \bigskip
- {\bf 4. Implementation}
-
- Bounded Queues are implemented by circular arrays. All operations take
- time $O(1)$. The space requirement is $O(n)$.
-
-