-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.py
41 lines (37 loc) · 914 Bytes
/
stack.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
40
41
class sta:
def __init__(self):
self.stack=list()
self.top=0
self.maxsize=4
def insert(self,data):
if(self.top>=self.maxsize):
print("Stack is Full")
else:
self.stack.append(data)
self.top+=1
def delete(self):
if(self.top<=0):
print("Stack is empty ")
else:
item=self.stack.pop()
self.top-=1
return(item)
def display(self):
print(self.stack)
obj=sta()
choice=1
while(choice!=0):
print("1.Insert into Stack")
print("2.Remove from Stack")
print("3.Display Stack")
print("4.Exit")
choice=int(input("Enter choice : "))
if(choice==1):
data=int(input("Enter data to insert : "))
obj.insert(data)
elif(choice==2):
print(obj.delete())
elif(choice==3):
obj.display()
else:
exit()