Queue
Queue
Queue
Learning outcomes
1 Definition of
Queue 5 Implementing a
queue With a List
2 Advantages and
Disadvantages of Queue 6 Implementing a
queue With Classes
3 Methods for
Queue in Python
4 Implementing a queue
With queue.Queue
Queue in Python is a linear data
structure with a rear and a front
QUE
DEFINITION
end, similar to a stack.
UE
• Queues are useful when a particular service is used
by multiple consumers.
• Queues are fast in speed for data inter-process
communication.
• Queues can be used in the implementation of other
data structures.
DISADVANTAGES
Dequeue Enqueue
REAR
METHODS FOR
QUEUE IN PYTHON!!
Enqueue Dequeue Peek
Adds a new element to the Removes and returns the first Returns the first element in
queue. (front) element from the the queue.
queue.
1 4 3 2
DEQUEUE 1
4 3 2
IMPLEMENTING A
queue With queue.Queue
UE
IMPLEMENTING A
WITH A LIST
queue
Since Python lists has good support for functionality needed to implement
queues, we start with creating a queue and do queue operations with just
a few lines
UE
IMPLEMENTING A
WITH A CLASS
queue
But to explicitly create a data structure for queues, with basic operations,
we should create a queue class instead. This way of creating queues in
Python is also more similar to how queues can be created in other
programming languages like C and Java.
QUE
IMPLEMENTING
WITH A CLASS
UE
PAALAM!!!!!