0% found this document useful (0 votes)
18 views23 pages

Queue New

Uploaded by

riyabhart02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views23 pages

Queue New

Uploaded by

riyabhart02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Queue

Queue
• A queue is a linear data structure that contains elements in an
ordered sequence. It is an abstract data type, pretty similar to a stack
data structure and also different fundamentally.
• We insert data at one end of the queue and remove data from the
other end.
• It follow First In First Out principle.
Real-life applications of queue
Here are a few more real-life applications of queues:
• Luggage checking machine
• Vehicles on toll tax bridge
• One way exits
• Patients waiting outside the doctor’s clinic
• Phone answering systems
• Cashier line in a store
• CPU scheduling- to keep track of processes for the CPU
• Handling website traffic - by implementing a virtual HTTP request
queue
• Printer Spooling - to store print jobs
• In routers - to control how network packets are transmitted or
discarded
• Traffic management - traffic signals use queues to manage
intersections
C++ Queue Methods
Methods Description

push() Inserts an element at the back of the queue.

Removes an element from the front of the


pop()
queue.

front() Returns the first element of the queue.

back() Returns the last element of the queue.

size() Returns the number of elements in the queue.

empty() Returns true if the queue is empty.


Types of Queues
• Simple Queue (Linear Queue): Basic queue where elements are
added at the rear and removed from the front.
• Circular Queue: The last position is connected back to the first to
make a circular queue, solving the limitation of unused space in a
linear queue.
• Priority Queue: Each element has a priority, and elements are
dequeued based on priority rather than just FIFO.
• Double-ended Queue (Deque): Insertion and deletion can occur at
both ends (front and rear).
Simple Queue
• In a simple queue, insertion takes place at the rear and removal
occurs at the front. It strictly follows the FIFO (First in First out) rule.

• Simple queue
Circular Queue
• In a circular queue, the last element points to the first element
making a circular link.
check for full queue has a new additional case:
•Case 1: FRONT = 0 && REAR == SIZE - 1
•Case 2: FRONT = REAR + 1
Deque (Double Ended Queue)
• In a double ended queue, insertion and removal of elements can be
performed from either from the front or rear. Thus, it does not follow
the FIFO (First In First Out) rule.
Types of Deque
• Input Restricted Deque
• In this deque, input is restricted at a single end but allows deletion at both
the ends.
• Output Restricted Deque
• In this deque, output is restricted at a single end but allows insertion at both
the ends.
Linear Queue: Array implementation
Linear Queue: Array implementation
Linear Queue: Array implementation
Queue: linked-list representation
• Maintain pointer to first and last nodes in a linked list;
• insert/remove from opposite ends
Circular Queue
Circular Queue
Double ended queue

You might also like