Queue New
Queue New
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
• 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