Liner Queue Copy. 1
Liner Queue Copy. 1
this method is inefficient use of array space. A stack push operation may result in stack overflow even
if there is space available in the array.
QUEUES
Queue is a linear data structure in which the insertion and deletion operations are performed at
two different ends. It is a collection of similar data items in which insertion and deletion operations
are performed based on FIFO (First In First Out) principle. In a queue data structure, adding and
removing of elements are performed at two different positions. The insertion is performed at one end
and deletion is performed at other end. In a queue data structure, the insertion operation is performed
at a position which is known as REAR and the deletion operation is performed at a position which is
known as FRONT.
Example
Queue after inserting 25, 30, 51, 60 and 85.
Operations on Queues
8
Downloaded by Sreya S ([email protected])
lOMoARcPSD|21950806
CIRCULAR QUEUE
Circular Queue is a linear data structure in which the operations are performed based on FIFO
(First In First Out) principle and the last position is connected back to the first position to make a
circle.
Graphical representation of a circular queue is as follows.
9
Downloaded by Sreya S ([email protected])
lOMoARcPSD|21950806
Now consider the following situation after deleting three elements from the queue.
In this case even if the queue is not full we cannot inset elements into that queue.
Operations on Circular Queue
enQueue(value) - Inserting value into the Circular Queue
In a circular queue, enQueue() is a function which is used to insert an element into the circular
queue. In a circular queue, the new element is always inserted at rear position. The enQueue() function
takes one integer value as parameter and inserts that value into the circular queue. We can use the
following steps to insert an element into the circular queue.
10
Downloaded by Sreya S ([email protected])
lOMoARcPSD|21950806
Double Ended Queue can be represented in TWO ways, those are as follows.
Input Restricted Double Ended Queue
Output Restricted Double Ended Queue
Input Restricted Double Ended Queue
In input restricted double ended queue, the insertion operation is performed at only one end and
deletion operation is performed at both the ends.
11
Downloaded by Sreya S ([email protected])
lOMoARcPSD|21950806
PRIORITY QUEUE
Priority queue is a variant of queue data structure in which insertion is performed in the order
of arrival and deletion is performed based on the priority.
There are two types of priority queues they are as follows.
1) Max Priority Queue
2) Min Priority Queue
1. Max Priority Queue
In max priority queue, elements are inserted in the order in which they arrive the queue and
always maximum value is removed first from the queue. For example assume that we insert in order 8,
3, 2, 5 and they are removed in the order 8, 5, 3, 2.
2. Min Priority Queue
Min Priority Queue is similar to max priority queue except removing maximum element first,
we remove minimum element first in min priority queue.
12
Downloaded by Sreya S ([email protected])