Created
June 6, 2023 13:21
-
-
Save cod3smith/a6eef994ea4a3d7756c95ad227b7b4f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Queue: | |
def __init__(self): | |
self.items = [] | |
def enqueue(self, item): | |
self.items.append(item) | |
def dequeue(self): | |
if not self.is_empty(): | |
return self.items.pop(0) | |
def is_empty(self): | |
return len(self.items) == 0 | |
def size(self): | |
return len(self.items) | |
# Example usage | |
queue = Queue() | |
queue.enqueue("Alice") | |
queue.enqueue("Bob") | |
queue.enqueue("Charlie") | |
print(queue.dequeue()) # Output: Alice | |
print(queue.dequeue()) # Output: Bob | |
print(queue.size()) # Output: 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment