-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
112ecfc
commit 7232466
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
class MyQueue: | ||
|
||
def __init__(self): | ||
self.array = [] | ||
self.head = 0 | ||
self.i = 0 | ||
|
||
def push(self, x: int) -> None: | ||
""" | ||
Push element x to the back of queue. | ||
""" | ||
self.array.append(x) | ||
|
||
def pop(self) -> int: | ||
""" | ||
Removes the element from in front of queue and returns that element. | ||
""" | ||
if len(self.array) > 0: | ||
a = self.array[0] | ||
self.array.pop(0) | ||
|
||
return a | ||
|
||
def peek(self) -> int: | ||
""" | ||
Get the front element. | ||
""" | ||
return self.array[0] | ||
|
||
def empty(self) -> bool: | ||
""" | ||
Returns whether the queue is empty. | ||
""" | ||
|
||
return self.array == [] | ||
|
||
|
||
# Your MyQueue object will be instantiated and called as such: | ||
# obj = MyQueue() | ||
# obj.push(x) | ||
# param_2 = obj.pop() | ||
# param_3 = obj.peek() | ||
# param_4 = obj.empty() |