Unit VI Queues
Unit VI Queues
Contents
• Basic concept: Queue as Abstract Data Type,
Representation of Queue using Sequential
organization, Queue Operations, Circular Queue and
its advantages, Multi-queues, Linked Queue and
Operations.
• Deque: Basic concept, types (Input restricted and
Output restricted), Priority Queue- Basic concept,
types (Ascending and Descending).
• Case Study: Priority queue in bandwidth
management
Quque
Quque
Queues
• Linear list.
• One end is called front.
• Other end is called rear.
• Additions are done at the rear only.
• Removals are made from the front only
• This mechanism is called First-In-First-Out
(FIFO).
Queues
• Placing an item in a queue is called “insertion
or enqueue”, which is done at the end of the
queue called “rear”.
• Removing an item from a queue is called
“deletion or dequeue”, which is done at the
other end of the queue called “front”.
• Some of the applications are: printer queue,
keystroke queue, etc.
Queue Operations
– IsEmpty … return true iff queue is empty
– Front … return front element of queue
– Rear … return rear element of queue
– Push/enqueue … add an element at the rear of the
queue
– Pop /dequeue… delete the front element of the
queue
Queue as ADT
• A queue is an ordered collection of items which are added at one end,
called the “rear,” and removed from the other end, called the “front.”
Queues maintain a FIFO ordering property. The queue operations are
given below.
• Queue() creates a new queue that is empty. It needs no parameters and
returns an empty queue.
• enqueue(item) adds a new item to the rear of the queue. It needs the
item and returns nothing.
• dequeue() removes the front item from the queue. It needs no
parameters and returns the item. The queue is modified.
• isEmpty() tests to see whether the queue is empty. It needs no
parameters and returns a boolean value.
• size() returns the number of items in the queue. It needs no parameters
and returns an integer.
Queue in an Array
– Use a 1D array to represent a queue.
– Suppose queue elements are stored with the front
element in queue[0], the next in queue[1], and so
on.
Queue in an Array
n-1 3 2 1 0
D C B A
After A leaves,
n-1 3 2 1 0
D C B
Dequeue()
Remedies
• Remedies.
– Don’t let the queue get full.
• When the addition of an element will cause the queue to be
full, increase array size.