Created
August 12, 2021 01:26
-
-
Save e96031413/8397fabb7ab52e4f292a6f1b65d47ceb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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