Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

Understand human resource planning in an academic setting.

Answered: 1 week ago

Question

Analyze mentoring and career planning opportunities for academics.

Answered: 1 week ago