Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started