-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queues - Program.py
65 lines (40 loc) · 1.26 KB
/
Queues - Program.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
#!/usr/bin/env python
# coding: utf-8
# In[ ]:
queue = []
queuesize = 5
while(True):
op = int(input("enter operation (1.enqueue,2.dequeue,3.display,4.front ele,5.rear ele,6.exit): "))
print("\n")
if op == 1:
if len(queue)<queuesize:
ele = int(input("Enter ele to add: "))
queue.append(ele)
print("pushing element ",ele,"\n")
else:
print("queue overflow")
elif op == 2:
if len(queue)==0:
print("queue underflow")
else:
print("removed element is: ",queue.pop(0),"\n")
elif op == 3:
if len(queue)==0:
print("queue is empty")
else:
print(queue,"\n")
elif op == 4:
if len(queue)==0:
print("queue is empty")
else:
print(queue[0])
elif op ==5:
if len(queue)==0:
print("queue is empty")
else:
print(queue[len(queue)-1],"\n")
elif op == 6:
print("exiting")
break
else:
print("enter proper option\n")