-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.py
47 lines (38 loc) · 799 Bytes
/
queue.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
import sys
queue = [None] * 3
print (queue)
head = tail = 0
qLen = 3
def deQueue():
global head
if head == tail:
print ('Underflow')
else:
print (queue[head])
head += 1
head %= qLen
def enQueue():
global tail
if (tail + 1) % qLen == head:
print ('Queue Overflow', file=sys.stderr)
else:
print('input value to en-queue')
queue[tail] = input()
tail += 1
tail %= qLen
print (queue)
operations = {
'd': deQueue,
'i': enQueue
}
while True:
print('Options available')
print('Type:')
print('i to en-queue')
print('d to de-queue')
print('e to exit')
option = input()
if(option == 'e'):
break
if option in operations:
operations[option]()