Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribedThis will be in Python. These are the directions. I understand how stacks work, but I do not know how queues work.

image text in transcribedThese 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 array

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

List the components of the strategic management process. page 72

Answered: 1 week ago