Queues - PowerPoint PPT Presentation

About This Presentation
Title:

Queues

Description:

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 ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 9
Provided by: stef91
Category:
Tags: queues | register | shift

less

Transcript and Presenter's Notes

Title: Queues


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
dataMAXQSIZE queue void enqueue(queue
p , int v) if
(isFull(p)) printf(queue is
full \n) else
p-gtdatap-gtrear v
p-gtrear 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

new item
2
front
back
1
1
2
3
4
1
1
2
2
3
4
Write a Comment
User Comments (0)
About PowerShow.com