Learn Before
Concept

Queue

A queue is a data structure that stores elements in a "first in, first out" (FIFO) manner. The least recently added item is the first element to be removed. An element is enqueued when it is added to the queue. An element is dequeued when it is removed from the queue.

A queue can be implemented using the collections module and deque class.

from collections import deque queue = deque() # Initialize queue structure # Enqueues the elements 20, 73 and 32 queue.append(20) queue.append(73) queue.append(32) # Queue now contains [20, 73, 32] print(queue) # Dequeue 20 queue.popLeft() # Queue now contains [73, 32] print(queue)

0

1

Updated 2021-04-13

Contributors are:

Who are from:

Tags

Python Programming Language

Data Science