1  #implementation of the queue using circular array
2  from array import array
3  class cirArray:
4     def __init__(self, maxSize):
5         self.count = 0
6         self.front = 0
7         self.back = maxSize - 1
8         self.qArray = array('i', [0] * maxSize)
9      #----------------------------
10     def isEmpty(self):
11        return self.count == 0
12     #----------------------------
13     def isFull(self):
14         return self.count == len(self.qArray)
15     #----------------------------
16     def length(self):
17         return self.count
18     #----------------------------
19     def enqueue(self, item, overflow):
20         if self.isFull():
21             overflow = True
22         else:
23             overflow = False
24             maxSize = len(self.qArray)
25            self.back = (self.back + 1) % maxSize
26            self.qArray[self.back] = item
27            self.count += 1
28        return overflow
29    #----------------------
30    def dequeue(self, item , underflow):
31        if self.isEmpty():
32            underflow = True
33        else:
34            underflow = False
35            item = self.qArray[self.front]
36            maxSize = len(self.qArray)
37            self.front = (self.front + 1) % maxSize
38            return item , underflow
39    #-------------------------
40    def printQueue(self):
41        for i in range(self.front, self.count):
42            print(self.qArray[i])
        
    #--------------------------------
