Stack using Collection Module in DSA Python
by DataFlair Team
Program 1
import collections
stack=collections.deque()
while(1):
print("\n----------------------------Stack Menu-------------------\n")
print("1.Push\n2.Pop\n3.Display\n4.Exit ")
print("\n------------------------------------------------------------\n")
choice=int(input("Enter your choice"))
if(choice==1):
n=int(input("Enter an element for push"))
stack.append(n)
elif(choice==2):
if(not stack):
print("Stack is empty")
else:
print("Poped element:",stack.pop())
elif(choice==3):
if(not stack):
print("Stack is empty")
else:
for element in stack:
print(element, end=" ")
else:
break
Tags: dsa pythondsa using pythondsa using python practicaldsa using python programstack using collection modulestack using collection module in dsa python
DataFlair Team
DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.