Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Queues CS-240 & CS-341 Dick Steflik

2 Queues First In, First Out operation - FIFO As items are added they are chronologically ordered, items are removed in their chronological order (oldest first)

3 Applications discrete event simulation - digital delay line task scheduling in an operation system staging area for data acquisition systems I/O buffers print queues sorting

4 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

5 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

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

7 Static Queue Implementation class Queue { public: Queue() {front = back = 0;} void enqueue(int v) { data[back++]= v; back=back %20;} int dequeue( ) { return data[front++] ; front = front % 20;} boolean isEmpty( ){ return front = = back} boolean isFull( ) { return ( front - back) == 1 private: int front, back; int data[20]; }


Download ppt "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."

Similar presentations


Ads by Google