-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
39 lines (33 loc) · 892 Bytes
/
stack.py
File metadata and controls
39 lines (33 loc) · 892 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,max=100):
self.stack=[]
self.maximum=max
def push(self,element):
if len(self.stack)==self.maximum:
print("Stack Overflow")
else:
self.stack.append(element)
def pop(self):
if len(self.stack)==0:
print("Stack is Empty")
else:
return self.stack.pop()
def display(self):
if len(self.stack)==0:
print("Stack is Empty")
else:
print(self.stack)
stack=Stack()
while True:
print("1->Push, 2->Pop, 3->Display, 4->Exit")
c=int(input('Enter your choice'))
if c==1:
a=input('Enter an element to be pushed')
stack.push(a)
elif c==2:
print('Popped element', stack.pop())
elif(c==3):
stack.display()
else:
print('Terminated')
break