Skip to content

Instantly share code, notes, and snippets.

@e96031413
Created Aug 12, 2021
Embed
What would you like to do?
# https://www.programiz.com/dsa/queue
# Queue implementation in Python
class Queue:
def __init__(self):
self.queue = []
# Add an element
def enqueue(self, item):
self.queue.append(item)
# Remove an element
def dequeue(self):
if len(self.queue) < 1:
return None
return self.queue.pop(0)
# Display the queue
def display(self):
print(self.queue)
def size(self):
return len(self.queue)
q = Queue()
q.enqueue(1)
q.enqueue(2)
q.enqueue(3)
q.enqueue(4)
q.enqueue(5)
q.display()
q.dequeue()
print("After removing an element")
q.display()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment