def enqueue(a,val):
a.append(val)
if len(a)==1:
front=rear=0
else:
rear=len(a)-1 #you may ask what about the front variable well,->https://youtu.be/Xw2Kmqwq-So?t=833
def dequeue(a):
if len(a)==0:
print("Empty Queue:")
else:
x=a.pop(0)
print("Dequeued Item=",x)
if len(a)==0:
front=rear=None
def peek(a):
if len(a)==0:
print("Empty queue:")
else:
front=0
print(a[front])
def display(a):
if len(a)==0:
print("Empty")
else:
for i in range(len[a])
print(a[i])
a=[]
front=rear=None
while True:
ch=int(input(int("1->Enqueue\n2->Dequeue\n3->peek\n4->Display\n5->Exit\nEnter your choice:"))
if ch==1:
val=int(input("Enter Value:"))
enqueue(a,val)
if ch==2:
dequeue(a)
if ch==3:
peek(a)
if ch==4:
display(a)
Comments
Post a Comment