Question: Circular, array - backed queue ( 1 2 points ) A queue can be build using fixed - size array to store its elements, and
Circular, arraybacked queue points
A queue can be build using fixedsize array to store its elements, and whose head and tail indices "wrap around" when they reach the end of the array. For this exercise you will complete this implementation so that it properly detects when it is full in which case it should raise a RuntimeError when enqueue is called and so that it can be resized when necessary using the resize method You will also implement an iter method that allows the queue to be iterated over from front head to back tail
The starter code can be found in class Queue found in the file circqueue.py You should not modify the init method, and your implementation should ensure that when dequeuing an item, its slot in the array is reset to None and that when the queue is emptied its head and tail attributes are reset to
Assume that resize will only be called with a value greater than the current length of the underlying array. Note that the underlying data container is a numpy array when you resize the queue, you should create a new numpy array of the appropriate size and copy the existing elements over to it
circqueue.py
import numpy as np
from typing import Any
class Queue:
def initself limit:
self.data npemptylimit dtypeobject
self.head
self.tail
self.count
def emptyself:
return self.count
def boolself:
return not self.empty
def strself:
if notself:
return
return joinstrx for x in self
def reprself:
return strself
## Don't change the above code!
def enqueueself val: Any:
raise NotImplementedError
def dequeueself Any:
raise NotImplementedError
def resizeself newsize: int:
assert lenselfdata newsize
raise NotImplementedError
def iterself:
raise NotImplementedError
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
