Modify the “CircularQueue” class so thecapacity automatically increases when you exceed the currentcapacity. When you try to add an item to a full queue, the capacityshould be doubled.
Do not decrease the capacity of the queue when you remove itemsfrom the queue.
You should include the entire CircularQueueclass definition in your answer to this question.
For example:
q = CircularQueue(2)q.enqueue(10)q.dequeue()q.enqueue(20)q.enqueue(30)q.enqueue(40)print(q.size())print(q.dequeue())print(q.dequeue())print(q.dequeue())
Result
3
20
3040
Original Code:
class CircularQueue:
def __init__(self,capacity):
self.items =[None]*capacity
self.MAX_QUEUE = capacity
self.front = 0
self.back = self.MAX_QUEUE – 1
self.count = 0
def is_full(self):
return self.count == self.MAX_QUEUE
def is_empty(self):
return self.count == 0
def enqueue(self,item):
if not self.is_full():
self.back = (self.back+1) % self.MAX_QUEUE
self.items[self.back] = item
self.count +=1
else:
raise IndexError(“The queue is full.”)
def dequeue(self):
if not self.is_empty():
item = self.items[self.front]
self.front =(self.front+1) % self.MAX_QUEUE
self.count
PayPal Gateway not configured
PayPal Gateway not configured