-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPush_pop.py
More file actions
49 lines (36 loc) · 987 Bytes
/
Push_pop.py
File metadata and controls
49 lines (36 loc) · 987 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
#Implement stack operations using list
stack=[]
def getChoice():
print("1.PUSH\n2.POP\n3.DISPLAY\n")
choice=int(input("Enter the choice:\n"))
return choice
def push(item):
stack.append(item)
def pop(item):
global stack
item = stack[-1]
del stack[-1]
return item
def display():
print("Elements of stack are",stack)
print("-----Implementation of stack-----")
choice = getChoice()
while choice != 4:
if(choice==1):
item=int(input("Enter the item to push:"))
push(item)
elif(choice==2):
if(len(stack) != 0):
item = pop(item)
print("Poped item",item)
else:
print("Satck underflow!!")
elif(choice==3):
if(len(stack) != 0):
display()
else:
print("Satck underflow!!")
else:
print("Invalid choice")
choice = getChoice()
print("Stack Operations Over")