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

Module 8 QUEUES

This document discusses queues, which are linear data structures that store items in a first-in, first-out (FIFO) manner. It describes common queue operations like insert (put), remove (get), check for emptiness, and check for fullness. It also discusses different types of queues like simple, circular, priority, and double-ended queues. The key aspects are that queues follow FIFO ordering and have efficient insert and remove operations at either end.
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)
27 views23 pages

Module 8 QUEUES

This document discusses queues, which are linear data structures that store items in a first-in, first-out (FIFO) manner. It describes common queue operations like insert (put), remove (get), check for emptiness, and check for fullness. It also discusses different types of queues like simple, circular, priority, and double-ended queues. The key aspects are that queues follow FIFO ordering and have efficient insert and remove operations at either end.
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

IT122

QUEUES
Joie Ann M. Mac
Objectives:
• To learn about Queues
• Operations
• Implementations
WHAT IS A QUEUE?
• A queue is a linear data structure that stores items in First In
First Out (FIFO) manner. With a queue the least recently
added item is removed first. A good example of queue is any
queue of consumers for a resource where the consumer that
came first is served first.
WHAT IS A QUEUE?
What are the Methods Available for
Queue in Python?
There are numerous methods available in Python to perform
operations on the queue. Some of the standard methods are:
• put(item): Inserts an element to the queue
• get(): Gets an element from the queue
• empty(): Checks and returns true if the queue is empty
• qsize: Returns queue’s length
• full(): Checks and returns true if the queue is full
• maxsize(): Maximum elements allowed in a queue
Basic Operations of Queue
A queue is an object (an abstract data structure - ADT) that
allows the following operations:
• Enqueue: Add an element to the end of the queue
• Dequeue: Remove an element from the front of the queue
• IsEmpty: Check if the queue is empty
• IsFull: Check if the queue is full
• Peek: Get the value of the front of the queue without
removing it
Working of Queue
Queue operations work as follows:
• two pointers FRONT and REAR
• FRONT track the first element of the queue
• REAR track the last element of the queue
• initially, set value of FRONT and REAR to -1
Enqueue Operation
• check if the queue is full
• for the first element, set the value of FRONT to 0
• increase the REAR index by 1
• add the new element in the position pointed to by REAR
Dequeue Operation
• check if the queue is empty
• return the value pointed by FRONT
• increase the FRONT index by 1
• for the last element, reset the values of FRONT and REAR to
-1
Types of Queues
A queue is a useful data structure in programming. It is similar to
the ticket queue outside a cinema hall, where the first person
entering the queue is the first person who gets the ticket.
There are four different types of queues:
• Simple Queue
• Circular Queue
• Priority Queue
• Double Ended Queue
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.
Circular Queue
• In a circular queue, the last element points to the first
element making a circular link.
Priority Queue
• A priority queue is a special
type of queue in which
each element is associated
with a priority and is
served according to its
priority. If elements with
the same priority occur,
they are served according
to their order in the queue.
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.

You might also like