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) examples: grocery store line, tube feed ammunition magazine, digital shift register,

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 front rear checkout

5 ADT Methods enqueue - add an item (at the back, move up as far as you can dequeue - return the value of the item at the front of the queue then delete the item and move all items forward one position. isEmpty - return false/true depending if the queue is empty; true if it is, false otherwise isFull – return false/ depending if the queue is empty; true if it is, false otherwise

6 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 make a type using a struct with two ints for the front and rear pointers and an array for the data part of the queue 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 typedef struct { int front,rear; int data[MAXQSIZE] queue; void enqueue(queue * p, int v) { if (isFull(p)) printf(“queue is full \n”); else { p->data[p->rear] = v; p->rear += 1; } int main() { queue q1 = {0}; enqueue(&q1,50); }

8 Priority Queues Operates like a queue except entry is at the back but items move up to the end of their priority list 11234 2 new item 11223 frontback 4


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