Unit III - Queue
Unit III - Queue
❑ Applications of Queue
Queue
7
Applications of Queue
Queues, like stacks, also arise quite naturally in the computer solution of many
problems.
The most common occurrence of a queue in computer applications is for the
scheduling of jobs.
In batch processing the jobs are ''queued-up'' as they are read-in and executed,
one after another in the order they were received.
Operations on Queue
Adding an element at the rear of the Queue
Delete the front element from the queue
PeepRear returns the rear element of the queue
PeepFront returns the front element of the queue
isFull returns if queue is full
isEmpty returns if queue is empty
Adding a element
Algorithm AddQ(q[],elem) int isfull()
{ { if(rear==size-1)
if(isfull()) return 1
front rear
Empty queue will have front and rear with the following conditions:
front->next=NULL
rear=NULL
---
rear = NULL;
front
Linked Queue and Operations
front rear
newNode
front rear
Enqueue operation: a) New node created b) New node inserted (Enqueue complete)
Linked Queue and Operations
front rear
front rear
24
Types of deque
● Input-restricted deque
Deletion can be made from both ends , but Insertion can be made
at one end only.
● Output-restricted deque
Insertion can be made at both ends , but Deletion can be made
from one end only.
25
deque Operations
● pushRear() - Insert element at back
● pushFront() - Insert element at front
● popRear() - Remove last element
● popFront() - Remove first element
● isEmpty() – Checks whether the queue is empty or not.
26
deque Example
Operation Deque content
pushFront(‘a’) [‘a’]
pushFront(‘b’) [‘b’ , ‘a’]
pushRear(‘c’) [‘b’ , ‘a’ , ‘c’]
27
Queue Applications: Job Scheduling