Queue

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

INTRODUCTION

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.

It stores items sequentially in a


FIFO (First In First Out) manner.

You can think of it as a customer

UE services queue that functions on a


first-come-first-serve basis.

To sum up, the item that is least


recently added to the list will be
removed first.
Queues can be implemented by using arrays

QUE or linked lists.

Queues can be used to implement job


scheduling for an office printer, order
processing for e-tickets

UE Queues are often mentioned together with


Stacks, a similar data structure discussed by
the previous reporter.
ADVANTAGES

QUE • A large amount of data can be managed efficiently


with ease.
• Operations such as insertion and deletion can be
performed with ease as it follows the first in first out
rule.

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

QUE • The operations such as insertion and deletion of


elements from the middle are time consuming.

• Searching an element takes time.

UE • Maximum size of a queue must be defined prior in


case of array implementation.
FIFO Representation of
Queue
FRONT

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.

NOTE: THERE ARE NUMEROUS METHODS AVAILABLE IN


PYTHON TO PERFORM OPERATIONS ON THE QUEUE.
METHODS FOR
QUEUE IN PYTHON!!
Empty Size Maxsize
Checks and returns true if Finds the number of elements Maximum elements allowed
the queue is empty in the queue in a queue

NOTE: THERE ARE NUMEROUS METHODS AVAILABLE IN


PYTHON TO PERFORM OPERATIONS ON THE QUEUE.
EMPTY Queue
ENQueue 3,1,4,3,2
3 1 4 3 2
DEQUEUE 3

1 4 3 2
DEQUEUE 1

4 3 2
IMPLEMENTING A
queue With queue.Queue

It is an in-built module for implementing a queue in Python. You


can use different functions available in the module to perform
operations on a queue. Below is an example of implementing a
queue with the help of a queue, along with the use of different
functions
Methods Available for
Queue queue.Queue

• 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
QUE
APPLICATION

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

Python list is used as a way of implementing queues. the list’s append()


and pop() methods can insert and delete elements from the queue.
however, while using this method, shift all the other elements of the list
by one to maintain the FIFO manner
QUE
IMPLEMENTING
WITH A LIST

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!!!!!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy