-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
31 lines (24 loc) · 685 Bytes
/
stack.py
File metadata and controls
31 lines (24 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'''
push(x) -- Push element x to the back of queue.
pop() -- Removes the element from in front of queue.
peek() -- Get the front element.
empty() -- Return whether the queue is empty.
'''
class Queue(object):
def __init__(self):
self.stack = []
def push(self, x):
self.stack += str(x)
def pop(self):
if len(self.stack) > 0:
self.stack.pop(0)
def peek(self):
if len(self.stack) == 0:
return None
else:
return int(self.stack[0])
def empty(self):
if len(self.stack) ==0:
return True
else:
return False