-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_list.py
40 lines (31 loc) · 858 Bytes
/
stack_list.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
class Stack:
def __init__(self) -> None:
self.stack = list()
def size(self) -> int:
return len(self.stack)
def is_empty(self) -> bool:
return not bool(len(self.stack))
def push(self, data: any) -> None:
self.stack.append(data)
def pop(self) -> any:
if not self.is_empty():
return self.stack.pop()
def peek(self) -> any:
if not self.is_empty():
return self.stack[-1]
def __str__(self) -> str:
return str(self.stack).replace(', ','->') \
.replace('[','').replace(']','')
def main():
pass
# s = Stack()
# s.push(1)
# s.push(2)
# s.push(3)
# print(s.pop())
# print(s.peek())
# print(s)
# print(s.size())
# print(s.is_empty())
if __name__ == '__main__':
main()