Question: Create a Max-PriorityQueue as a C++ class called PriorityQueue. It must implemented as an array-based binary heap with the root node at index 1 of

Create a Max-PriorityQueue as a C++ class called PriorityQueue. It must implemented as an array-based binary heap with the root node at index 1 of the array 1. The keys are non-negative integers. You must implement:

Construction : When your priority queue is created, an integer max_size must be passed to the priority queue. It is full if the number of items in the priority queue is equal to max_size

insert(Key k)

: Insert the key

k

into the priority queue. If the priority queue is full

and

insert

is called, print the following error and then exit:

PriorityQueue::insert called on full priority queue

removeMax()

: Remove the maximum key from the priority queue. If the priority queue

is empty and

removeMax

is called, print the following error and then exit:

PriorityQueue::removeMax called on an empty priority queue

removeKey(Key k)

: Remove the key

k

from the priority queue. If this key does not

exist in the priority queue, print the following error and then exit (in this example,

k = 45

):

PriorityQueue::removeKey key 45 not found

change(Key k, Key newK)

: Change the key

k

to the key

newK

. If this key does not

exist in the priority queue, print the following error and then exit (in this example,

k = 63

):

PriorityQueue::change key 63 not found

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!