-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQUEUEPRG.PY
79 lines (76 loc) · 1.93 KB
/
QUEUEPRG.PY
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def isEmpty(Que):
if Que==[]:
return True
else:
return False
def Enqueue(Que,item):
Que.append(item)
if len(Que)==1:
front=rear=0
else:
rear=len(Que)-1
def Dequeue(Que):
if isEmpty(Que):
return "Underflow"
else:
item=Que.pop(0)
if len(Que)==0:
front=rear=None
return item
def Peek(Que):
if isEmpty(Que):
return "underflow"
else:
front=0
return Que[front]
def Display(Que):
if isEmpty(Que):
print("Queue Empty!")
elif len(Que)==1:
print(Que[0],"<==front,rear")
else:
front=0
rear=len(Que)-1
print(Que[front],"<-front")
for a in range (1,rear):
print(Que[a])
print(Que[rear],"<-rear")
#___main______
Queue=[]
front=None
while True:
print("Menu for Queue operation")
print("1.Enqueue")
print("2.Dequeue")
print("3.Peek")
print("4.Display Queue")
print("5.Exit")
ch=int(input("Enter your choice(1-5):"))
if ch==1:
item1=input("enter ur name")
item2=int(input("Enter Roll No:"))
item=[item1,item2]
Enqueue(Queue,item)
# input("Press Enter to continue")
elif ch==2:
item=Dequeue(Queue)
if item=="Underflow":
print("Underflow!Queue is Empty!")
else:
print("Dequeued item is ",item)
# input("Press Enter to continue")
elif ch==3:
item=Peek(Queue)
if item=="underflow":
print("Underflow! Queue is Empty")
else:
print("Frontmost item is ",item)
input("Press Enter to continue")
elif ch==4:
Display(Queue)
input("Press Enter to continue")
elif ch==5:
break
else:
print("Invalid Choice")
input("Press Enter to continue")