Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement a class StatQueue (inheriting from the class LinkedQueue in the Python file linked_queue.py) to support additional operations, including min(), max(), and mean(), which return

image text in transcribed
Implement a class StatQueue (inheriting from the class LinkedQueue in the Python file linked_queue.py) to support additional operations, including min(), max(), and mean(), which return the minimum, maximum, and mean values of the elements in the queue, respectively. Assuming the elements in the queue are numbers. These above operations should run in a constant time; this means that you should maintain corresponding member variables to store minimum, maximum and mean element values (you can name them_min, max, and _mean respectively). These member variables should be updated each time either when dequeue or enqueue operations are performed. Such that the operations dequeue() and enqueue(e) should be rewrote in the StatQueue class to support updating these member variables. The StatQueue class should continue supporting all other regular operations, such as first(), len(), and is empty0, by inheriting them from the LinkedQueue class without further implementation. Note: When you implement (rewrite) dequeue() in the StatQueue class, you should write code to check whether the value of the removed element is the_min or max. If yes, you should conduct a search among the elements for the minimum or maximum values and update the min or max correspondingly. Similarly, you should update_min and_max in enqueue(e) method when it is needed, the only difference is that it does not require a search for minimum or maximum value in the enqueue operation. The mean should be updated in both enqueue(e) or dequeue() methods, it does not matter whether the to-be-removed element is minimum maximum or not. Implement a class StatQueue (inheriting from the class LinkedQueue in the Python file linked_queue.py) to support additional operations, including min(), max(), and mean(), which return the minimum, maximum, and mean values of the elements in the queue, respectively. Assuming the elements in the queue are numbers. These above operations should run in a constant time; this means that you should maintain corresponding member variables to store minimum, maximum and mean element values (you can name them_min, max, and _mean respectively). These member variables should be updated each time either when dequeue or enqueue operations are performed. Such that the operations dequeue() and enqueue(e) should be rewrote in the StatQueue class to support updating these member variables. The StatQueue class should continue supporting all other regular operations, such as first(), len(), and is empty0, by inheriting them from the LinkedQueue class without further implementation. Note: When you implement (rewrite) dequeue() in the StatQueue class, you should write code to check whether the value of the removed element is the_min or max. If yes, you should conduct a search among the elements for the minimum or maximum values and update the min or max correspondingly. Similarly, you should update_min and_max in enqueue(e) method when it is needed, the only difference is that it does not require a search for minimum or maximum value in the enqueue operation. The mean should be updated in both enqueue(e) or dequeue() methods, it does not matter whether the to-be-removed element is minimum maximum or not

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

Database Design And Implementation

Authors: Shouhong Wang, Hai Wang

1st Edition

1612330150, 978-1612330150

More Books

Students also viewed these Databases questions