-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathQueueUsingList.py
28 lines (25 loc) · 1.08 KB
/
QueueUsingList.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
try: #try catch so that the program does not crash
queue=[]
while True:
op = int(input("Press--> 1 to insert into queue | 2 to remove from queue | 3 to display values of queue | 4 to reverse the exisiting queue| 5 to exit "))
if op==1: #to insert an elelment in the queue
ele = int(input("enter elem to insert "))
queue.append(ele)
elif op==2: #to remove an element from the queue
if len(queue) ==0:
print("The queue is empty, insert values if required")
else:
ele=queue.pop(0)
print(ele)
elif op==3: #to display the elements in the queue
print(queue)
elif op==4: #to reverse queue
queue.reverse()
elif op==5: #to exit
break
else:
print("invalid option")
except ValueError:
print("Please enter integer only") #If user inputs an alphabet or string the program should not crash
except:
print("There's been some issue please check the data you've entered")