-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueue_Op.py
More file actions
49 lines (36 loc) · 1007 Bytes
/
Queue_Op.py
File metadata and controls
49 lines (36 loc) · 1007 Bytes
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
#Implement Queue operations using list
Queue=[]
def getChoice():
print("1.INSERT\n2.DELETE\n3.DISPLAY\n")
choice=int(input("Enter the choice:\n"))
return choice
def insert(item):
Queue.append(item)
def delete(item):
global Queue
item = Queue[0]
del Queue[0]
return item
def display():
print("Elements of stack are",Queue)
print("-----Implementation of Queue-----")
choice = getChoice()
while choice != 4:
if(choice==1):
item=int(input("Enter the item to insert:"))
insert(item)
elif(choice==2):
if(len(Queue) != 0):
item = delete(item)
print("Deleted item = ",item)
else:
print("Queue underflow!!")
elif(choice==3):
if(len(Queue) != 0):
display()
else:
print("Queue underflow!!")
else:
print("Invalid choice")
choice = getChoice()
print("Queue Operations Over")