Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This will be in Python. These are the directions. I understand how stacks work, but I do not know how queues work. These are the
This will be in Python. These are the directions. I understand how stacks work, but I do not know how queues work.
These are the functions that I need to implement for the class. I do not know how to do it.
Overview For this assignment you will implement a circular, array-backed queue data structure. In the following class, which you are to complete, the backing array will be created and populated with None s in the init method, and the head and tail indexes set to sentinel values (you shouldn't need to modify _init__). Enqueueing and Dequeueing items will take place at the tail and head, with tail and head tracking the position of the most recently enqueued item and that of the next item to dequeue, respectively. To simplify testing, your implementation should make sure that when dequeuing an item its slot in the array is reset to None , and when the queue is emptied its head and tail attributes should be set to-1 Because of the fixed size backing array, the enqueue operation is defined to raise a RuntimeError when the queue is full - the same exception should be raised when dequeue is called on an empty queue. Finally, the resize method will allow the array underlying the queue to be increased in size. It is up to you how to implement this (you can either leave the elements in their current positions, though this may require "unwrapping" elements, or you can simply move all elements towards the front of the array). You may assume that resize will only be called with a value greater than the current length of the underlying array. Overview For this assignment you will implement a circular, array-backed queue data structure. In the following class, which you are to complete, the backing array will be created and populated with None s in the init method, and the head and tail indexes set to sentinel values (you shouldn't need to modify _init__). Enqueueing and Dequeueing items will take place at the tail and head, with tail and head tracking the position of the most recently enqueued item and that of the next item to dequeue, respectively. To simplify testing, your implementation should make sure that when dequeuing an item its slot in the array is reset to None , and when the queue is emptied its head and tail attributes should be set to-1 Because of the fixed size backing array, the enqueue operation is defined to raise a RuntimeError when the queue is full - the same exception should be raised when dequeue is called on an empty queue. Finally, the resize method will allow the array underlying the queue to be increased in size. It is up to you how to implement this (you can either leave the elements in their current positions, though this may require "unwrapping" elements, or you can simply move all elements towards the front of the array). You may assume that resize will only be called with a value greater than the current length of the underlying arrayStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started