0% found this document useful (0 votes)
14 views

6.queue

A queue is a linear data structure that operates on a First In First Out (FIFO) basis, with insertion at the rear and deletion at the front. It has various applications including waiting lists, data transfer, and operating system interrupts, and can be implemented using arrays or linked lists. Additionally, there are specialized types of queues such as circular queues, deques, and priority queues, each with unique operations and characteristics.

Uploaded by

sumeet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

6.queue

A queue is a linear data structure that operates on a First In First Out (FIFO) basis, with insertion at the rear and deletion at the front. It has various applications including waiting lists, data transfer, and operating system interrupts, and can be implemented using arrays or linked lists. Additionally, there are specialized types of queues such as circular queues, deques, and priority queues, each with unique operations and characteristics.

Uploaded by

sumeet
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

6.

QUEUE
Queue
• A Queue is defined as a linear data structure that is open at both ends.
Insert operation is performed at one end called REAR and delete
operation is performed at another end called FRONT
• in First In First Out (FIFO) order.
Applications of Queue
1.Queues are widely used as waiting lists for a single shared resource
like printer, disk, CPU.
2.Queues are used in asynchronous transfer of data (where data is not
being transferred at the same rate between two processes) for eg.
pipes, file IO, sockets.
3.Queues are used as buffers in most of the applications like MP3 media
player, CD player, etc.
4.Queue are used to maintain the play list in media players in order to
add and remove the songs from the play-list.
5.Queues are used in operating systems for handling interrupts.
Queue as ADT
• The most fundamental operations in the queue ADT include:
• enqueue(): is a data manipulation operation that is used to insert
elements into the queue.
• dequeue(): is a data manipulation operation that is used to remove
elements from the queue.
• peek(): is an operation that is used to retrieve the frontmost element in
the queue, without deleting it.
• isFull(): The isFull() operation verifies whether the queue is full
• isEmpty(): operation verifies whether the queue is empty.
• Size(): Returns total no, of elements present in queue
Queue using Linked List implementation

• array implementation can not be used for the large scale applications where the
queues are implemented. One of the alternative of array implementation is
linked list implementation of queue.
• In a linked queue, each node of the queue consists of two parts i.e. data part
and the link part. Each element of the queue points to its immediate next
element in the memory.
• In the linked queue, there are two pointers maintained in the memory i.e. front
pointer and rear pointer. The front pointer contains the address of the starting
element of the queue while the rear pointer contains the address of the last
element of the queue.
Circular Queue
• A Circular Queue is an extended version of a normal queue where the last
element of the queue is connected to the first element of queue forming a
circle.

• In a normal Queue, we can insert elements until the queue becomes
full. However once the queue becomes full, we can not insert the next
element even if there is a space in front of the queue.
Operations on Circular Queue:
• Front: Get the front item from the queue.
• Rear: Get the last item from the queue.
• enqueue(value) This function is used to insert an element into the circular
queue. In a circular queue, the new element is always inserted at the rear
position.
• Check whether the queue is full – [i.e., the rear end is in just before the front end in a
circular manner].
• If it is full then display Queue is full.
• If the queue is not full then, insert an element at the end of the queue.
• dequeue() This function is used to delete an element from the circular
queue. In a circular queue, the element is always deleted from the front
position.
• Check whether the queue is Empty.
• If it is empty then display Queue is empty.
• If the queue is not empty, then get the last element and remove it from the queue.
Illustration of Circular Queue Operation
Deque
The deque stands for Double Ended Queue. Deque is a linear data structure where the
insertion and deletion operations are performed from both ends. We can say that deque is a
generalized version of the queue.
Types of deque
There are two types of deque -
• Input restricted queue
• Output restricted queue
Input restricted Queue
In input restricted queue, insertion operation can be performed at only one
end, while deletion can be performed from both ends.
• Output restricted Queue
• In output restricted queue, deletion operation can be performed at only one
end, while insertion can be performed from both ends.
Priority Queue
• It is a special type of queue in which the elements are arranged based on the
priority. It is a special type of queue data structure in which every element
has a priority associated with it. Suppose some elements occur with the
same priority, they will be arranged according to the FIFO principle. The
representation of priority queue is shown in the below image -
Priority Queue
• Insertion in priority queue takes place based on the arrival, while deletion in
the priority queue occurs based on the priority. Priority queue is mainly
used to implement the CPU scheduling algorithms.
• There are two types of priority queue that are discussed as follows -
• Ascending priority queue - In ascending priority queue, elements can be
inserted in arbitrary order, but only smallest can be deleted first. Suppose an
array with elements 7, 5, and 3 in the same order, so, insertion can be done
with the same sequence, but the order of deleting the elements is 3, 5, 7.
• Descending priority queue - In descending priority queue, elements can be
inserted in arbitrary order, but only the largest element can be deleted first.
Suppose an array with elements 7, 3, and 5 in the same order, so, insertion
can be done with the same sequence, but the order of deleting the elements
is 7, 5, 3.

You might also like