-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCircular Queue.py
More file actions
44 lines (40 loc) · 816 Bytes
/
Circular Queue.py
File metadata and controls
44 lines (40 loc) · 816 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
QEnd = 2
Array = [""]*QEnd
QEnd-=1
QSize = 0
Front = 0
Rear = 0
def Join(value):
global QEnd
global Rear
global Array
global QSize
if QSize<QEnd:
Array[Rear]=value
Rear+=1
QSize+=1
if Rear==QEnd and QSize<QEnd:
#wrap around
Rear=0
else:
print("Queue is full.")
def Leave():
global QEnd
global Front
global Array
global QSize
if QSize<=0:
value = "Queue is empty"
else:
value = Array[Front]
Front +=1
QSize-=1
if QSize==0 and Front==QEnd:
Front = 0
return value
Join("Faheem")
Join("Ali")
print(Leave())
Join("Kaleem")
print(Leave())
print(Leave())