Question
Supply the missing code. Complete the program together with a printout of a run of the program. An attempt to remove from an empty priority
Supply the missing code. Complete the program together with a printout of a run of the program. An attempt to remove from an empty priority queue should result in a call to exit.
#include
PriorityQueue::PriorityQueue() { _size = 0; } int main(){ PriorityQueue pq; Item a(1, 2), b(3, 1), c(4, 6), d(15, 4), e(5, 3), f(10, -2), g(5, 10), h(7, -4), i(12, -5); pq.insert(a); pq.insert(b); pq.insert(c); pq.insert(d); pq.insert(e); pq.insert(f); pq.insert(g); pq.insert(h); pq.insert(i); pq.print(); cout << "---------------------- "; while( !pq.isEmpty() ) { Item temp; temp = pq.remove(); cout << "key = " << temp._key << " value = " << temp._value << ; } } void PriorityQueue::insert(Item item) { // Missing code
} Item PriorityQueue::remove(){ // Missing code } void PriorityQueue::print(){ for( int i = 1; i <= _size; i++ ) cout << "value = " << _data[i]._value << " key = " << _data[i]._key << ; }
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