forked from yshshrm/Algorithms-And-Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstack.py
More file actions
39 lines (30 loc) · 713 Bytes
/
Copy pathstack.py
File metadata and controls
39 lines (30 loc) · 713 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
32
33
34
35
36
37
38
39
class Stack:
def __init__(self):
self._data = []
def push(self, x):
self._data.append(x)
def pop(self):
x = self._data[len(self._data) - 1]
del self._data[len(self._data) - 1]
return x
def peek(self):
return self._data[len(self._data) - 1]
def empty(self):
self._data = []
def test():
stack = Stack()
stack.push(1)
stack.push(2)
stack.push(3)
print(stack.pop())
print(stack.pop())
stack.empty()
stack.push(4)
stack.push(5)
print(stack.peek())
stack.push(6)
print(stack.pop())
print(stack.pop())
print(stack.pop())
if __name__ == '__main__':
test()