Created
October 26, 2017 06:30
-
-
Save hoanbka/27f7462e80930058a5b62b6a6ef27e07 to your computer and use it in GitHub Desktop.
Implementation of a simple Queue
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
## Implement Queue in Python | |
class Queue(): | |
def __init__(self): | |
self.arr = [] | |
def push(self, item): | |
self.arr.insert(0, item) | |
def pop(self): | |
if self.arr: | |
self.arr.pop() | |
else: | |
return 'Queue is Empty' | |
def poll(self): | |
if self.arr: | |
return self.arr[-1] | |
else: | |
return 'Queue is Empty' | |
def size(self): | |
return len(self.arr) | |
def __str__(self): | |
return str(self.arr) | |
q = Queue() | |
print(q) | |
q.push(5) | |
q.push(6) | |
q.push(10) | |
print(q) | |
q.pop() | |
print(q) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment