-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_implementaion.py
More file actions
44 lines (33 loc) · 903 Bytes
/
stack_implementaion.py
File metadata and controls
44 lines (33 loc) · 903 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
40
41
42
43
44
from my_linkedlist_implementation import LinkedList
class Stack:
def __init__(self, unique: bool = False):
self.__data_list = LinkedList(unique_data=unique)
def push(self, data):
return self.__data_list.insert_head(data)
def pop(self):
return self.__data_list.delete_head()
def peek(self):
return self.__data_list.head.data
def is_empty(self):
return self.__data_list.head is None
def size(self):
return len(self.__data_list)
def __repr__(self):
return self.__data_list.__repr__()
if __name__ == "__main__":
s = Stack(True)
s.push(1)
s.push(2)
s.push(5)
s.push(3)
print(s.size())
print(s.pop())
print(s.size())
print(s.pop())
print(s.size())
print(s.is_empty())
print(s.pop())
print(s.size())
print(s.pop())
print(s.size())
print(s.is_empty())