-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.py
More file actions
46 lines (31 loc) · 1.02 KB
/
Stack.py
File metadata and controls
46 lines (31 loc) · 1.02 KB
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
46
from DoubleLinkedList import DoubleLinkedList
class Stack(DoubleLinkedList):
def __init__(self):
super().__init__()
def push(self,item : object) -> None:
self.add_at_end(item)
def pop(self) -> object:
if not self.is_empty():
return self.delete_from_end()
def is_empty(self) -> bool:
if self.size == 0:
print("Stack is empty")
return True
return False
def print_stack(self) -> None :
self.print_list()
def insert_at_beginning(self,item):
raise NotImplementedError("Insert at Begining is not allowed in Stack.")
def insert(self, pos, item):
raise NotImplementedError("This operation is not allowed in Stack.")
def delete(self, pos):
raise NotImplementedError("This operation is not allowed in Stack.")
def main():
s = Stack()
s.push(3)
s.push(4)
print(s.pop())
print(s.pop())
print(s.pop())
if __name__ == "__main__":
main()