-
Notifications
You must be signed in to change notification settings - Fork 2
/
queue.py
45 lines (38 loc) · 787 Bytes
/
queue.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Stack(object):
"""docstring for Stack"""
def __init__(self):
super(Stack, self).__init__()
self.stack = []
def push(self, item):
self.stack.append(item)
def pop(self):
self.stack.pop()
def size(self):
return len(self.stack)
def peek(self):
return self.stack[-1]
def is_empty(self):
if len(self.stack) < 1:
return "Yes, it's empty"
return "No, the size is {}".format(stack.size())
def display(self):
return self.stack
stack = Stack()
stack.push(1)
stack.push(2)
stack.push(3)
stack.push(4)
stack.push(2)
print(stack.peek())
print(stack.is_empty())
print(stack.display())
stack.pop()
print(stack.display())
stack.pop()
print(stack.display())
stack.pop()
stack.pop()
print(stack.display())
stack.pop()
print(stack.display())
print(stack.is_empty())