Static Queue in DSA Python
by DataFlair Team
Program 1
# Static implementation of Queue
import os
MAXSIZE=10
rear=-1
front=-1
myqueue=[] # Queue
def myinsert():
global rear
global front
global MAXSIZE
if(rear==MAXSIZE-1):
print("Queue is oeverflow")
else:
n=int(input("Enter an element: "))
if(rear==-1 and front==-1):
rear=front=0
else:
rear=rear+1
myqueue.insert(rear,n)
def mydelete():
global rear
global front
global MAXSIZE
if(len(myqueue)==0):
print("Queue is empty")
else:
print("Deleted element is: ",myqueue[front])
del myqueue[front]
front=front+1
def mydisplay():
global rear
global front
global MAXSIZE
if(len(myqueue)==0):
print("Queue is empty")
else:
print("Elements of queue: ")
for element in myqueue:
print(element)
# Main
os.system('cls')
while(1):
print("\n-----------------------Queue Menu------------------------")
print("1. Insert \n 2. Delete \n 3. Display \n 4. Exit")
print("-------------------------------------------------------------")
choice=int(input("Enter your choice: "))
if(choice==1):
myinsert()
elif(choice==2):
mydelete()
elif(choice==3):
mydisplay()
else:
break
Tags: dsa pythondsa python practicaldsa python programdsa python program on static queuestatic queuestatic queue in dsa pythonstatic queue in dsa with 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.