Question: Implement a Priority Queue using a binary heap and following the interface shown below. template struct PriorityQueue { R * rank; V * value; int

Implement a Priority Queue using a binary heap and following the interface shown below.
template
struct PriorityQueue {
R * rank;
V * value;
int values;
int size;
};
template void initialize(PriorityQueue &pq,int size);
template void destroy(PriorityQueue &pq);
template void insert(PriorityQueue &pq,R rank,V value);
template V pop(PriorityQueue &pq);
template int size(PriorityQueue &pq)
The pointers rank and value should reference "parallel" arrays holding the key-value pairs currently in the priority queue.
initialize() sets up the data structure
destroy() cleans up the before it goes out of scope
insert() adds value with rank
pop() removes and returns highest ranked value
size() reports the current size (cardinality)
The initial size of the queue is determined by a parameter. It should be doubled as needed.
You can test your code using something like the following code. Obviously you should expand the following to fully test your code.

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!