60 likes | 247 Views
Queues. CS-240 & CS-341 Dick Steflik. Queues. First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed in their chronological order (oldest first). Applications. discrete event simulation - digital delay line
E N D
Queues CS-240 & CS-341 Dick Steflik
Queues • First In, First Out operation - FIFO • As items are added they are chronologically ordered, items are removed in their chronological order (oldest first)
Applications • discrete event simulation - • digital delay line • task scheduling in an operation system • staging area for data acquisition systems • I/O buffers • print queues
Normal methods • constructor - create and initialize a queue object • copy constructor - create a queue object that is a duplicate of another existing queue object (this method is needed to insure correct value semantics) • overloaded assignment operator - assign the value of an existing queue object (a) to another existing queue object (b) so that the result is that b is a duplicate of a (this method is needed to insure correct value semantics) • destructor - destroy a queue object by returning any of its dynamic storage back to the heap and setting its static elements to NULL or zero
Methods • enqueue - add an item (at the back) • dequeue - return the value of the item at the front of the queue then delete the item • isEmpty - return false/true depending if the queue is empty; true if it is, false otherwise
Private data strategies • use an array to hold items and use an int as an index for the array to indicate where the back of the queue is • same as above, but use a dynamic array • same as above but treat array as if it were circular and use two ints, one to indicate the front and the other to indicate the back • use a struct to define a node and add nodes dynamically as they are needed; use one static pointer to a node to point at the fron node and another to point at the back node.