-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp21.py
More file actions
52 lines (46 loc) · 1.02 KB
/
Copy pathp21.py
File metadata and controls
52 lines (46 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
47
48
49
50
51
52
def isempty(stk):
if stk==[ ]:
return True
else:
return False
def push(stk,ele):
stk.append(ele)
print("Element inserted..")
print(stk)
def POP(stk):
if isempty(stk):
print("Stack is empty.....")
else:
print("Deleted element:",stk.pop())
def Peek(stk):
if isempty(stk):
print("Stack is empty...")
else:
print("Element at the top is:",stk[-1])
def Display(stk):
if isempty(stk):
print("Stack is empty...")
else:
for i in range(len(stk)-1,-1,-1):
print(stk[i])
stack=[ ]
while True:
print("************Stack operations**************")
print("1. PUSH")
print("2. POP")
print("3. PEEK")
print("4. DISPLAY")
print("5. EXIT")
choice=int(input("Enter a choice:"))
if choice==1:
elt=int(input("Enter an element you want to insert:"))
push(stack,elt)
elif choice==2:
POP(stack)
elif choice==3:
Peek(stack)
elif choice==4:
Display(stack)
else:
choice==5
break