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 #include using namespace std; struct Item { public: int _value; int _key; Item(int, int ); // class constructor Item(){_value = 0; _key = 0;} // default class constructor }; Item::Item(int value, int key) { _value = value; _key = key; } class PriorityQueue { private: enum {_maxSize = 256}; int _size; Item _data[_maxSize]; public: PriorityQueue(); //default constructor bool isEmpty(){ return ! _size; } void insert(Item); Item remove(); void print(); };

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

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!