Question: Implement a MaxQueue data structure as a singly - linked list, that can store comparable ele - ments. MaxQueue supports the usual FIFO Queue operations
Implement a MaxQueue data structure as a singlylinked list, that can store comparable ele
ments. MaxQueue supports the usual FIFO Queue operations addx remove and size
In addition, it supports a max operation, which returns the maximum value currently stored
in the data structure. You have to modify the file MaxQueue.py that is included in the same
Beachboard folder as these instructions.
Hint: Consider storing elements into a singlylinked list and into a doublylinked list using
the following algorithms:
Adding an element: When a new element is added to the MaxQueue, it is added to the
tail of the singlylinked queue, regardless of its value. Moreover,
if the element is larger than the current max which is stored at the head of the
doublylinked list then the doublylinked list is emptied out, and the new element
gets placed in the head as the new the max.
if the element is smaller than the current max, the element gets placed in the
doublylinked list in decreasing order. Discard any elements existing in the doubly
linked list that are smaller than this new element. This is because they will be re
moved from the singlylist queue before the newlyadded element, and thus will
never have the chance to be the max element of the queue.
Removing an element: When an element is removed, it is removed from the head of
the singlylinked queue. Moreover, if the removed element was the maximum element,
the head of the doublylinked list must also be removed.
Example:
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
