The queue data abstraction, Include files, Declaration and initialization of queue – HP Integrity NonStop H-Series User Manual

Page 115: Example program - bank teller simulation

Advertising
background image

Click on the banner to return to the user guide home page.

©Copyright 1996 Rogue Wave Software

The Queue Data Abstraction

As a data abstraction, a

queue

is traditionally defined as any object that implements the following

operations:

empty()

return true if the collection is empty

size()

return number of elements in collection

front()

return (but do not remove) the element at the front of the queue

back()

return the element at the end of the queue

push(newElement) push a new element on to the end of the queue

pop()

remove (but do not return) the element at the front of the queue

Include Files

Note that the operations of accessing and of removing the front elements are performed separately.
Programs that use the queue data abstraction should include the file queue, as well as the include
file for the container type (e.g., list).

# include <queue>
# include <list>

Declaration and Initialization of queue

A declaration for a queue must specify both the element type as well as the container that will hold
the values. For a queue the most common containers are a

list

or a

deque

. The list version is

generally smaller, while the deque version may be slightly faster. The following are sample
declarations for a queue.

queue< int, list<int> > queueOne;
queue< double, deque<double> > queueTwo;
queue< Part *, list<Part * > > queueThree;
queue< Customer, list<Customer> > queueFour;

The last example creates a queue of a programmer-defined type named Customer. As with the stack
container, all objects stored in a queue must understand the operators < and ==.

Because the queue does not implement an iterator, none of the generic algorithms described in
Sections

13

or

14

apply to queues.

Advertising
This manual is related to the following products: