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 initializePriorityQueue &pqint size;
template void destroyPriorityQueue &pq;
template void insertPriorityQueue &pqR rank,V value;
template V popPriorityQueue &pq;
template int sizePriorityQueue &pq
The pointers rank and value should reference "parallel" arrays holding the keyvalue 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
