-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
50 lines (35 loc) · 918 Bytes
/
Copy pathstack.py
File metadata and controls
50 lines (35 loc) · 918 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
45
46
47
48
49
50
class Stack:
def __init__(self):
self.items = []
def push(self, val):
self.items.append(val)
def pop(self):
if self.isEmpty():
return "Stack is empty"
return self.items.pop()
def isEmpty(self):
return self.items == []
def size(self):
return len(self.items)
def main():
obj = Stack()
# preload stack with list values
lst = [1, 2, 3, 4]
for i in lst:
obj.push(i)
print("1. Push")
print("2. Pop")
print("3. Is Empty")
c = int(input("Enter your choice: "))
if c == 1:
val = int(input("Enter value to push: "))
obj.push(val)
print("Stack:", obj.items)
elif c == 2:
print("Popped value:", obj.pop())
print("Stack:", obj.items)
elif c == 3:
print("Is stack empty?", obj.isEmpty())
else:
print("Invalid choice")
main()