Question: Need a miracle and help with this problem( Number 2 and Number 1) given to us last minute. Please use C++ only. I'm also using

Need a miracle and help with this problem( Number 2 and Number 1) given to us last minute.

Please use C++ only. I'm also using CodeLite as the editior. Only given the header file for heap and priority_queue (Both files are below). They are needed for this program. Need the template for heap and priority_queue. Need a test program for this as well(the main.cpp)

This is from the Data Structures and Other Objects Using C++ 4th edition Book.

Need a miracle and help with this problem( Number 2 and Number1) given to us last minute. Please use C++ only. I'm also

#ifndef _HEAP_H_ #define _HEAP_H_

#include #include

// This class implements an unbounded max heap.

// class invariant: heap property is satisfied for a max heap

template class heap { public: heap(); // postcondition: empty heap has been created unsigned int size() const; // postcondition: number of elements in a heap has been returned bool is_empty() const; // postcondtion: returned whether the heap is empty void insert (const T& item); // postcondition: item has been added void remove(); // precondition: heap is not empty // postcondition: largest item has been removed from the heap T max() const; // precondition: heap is not empty // postcondition: copy of largest element in the heap has been returned T& max(); // precondition: heap is not empty // postcondition: access to largest element in the heap has been returned private: std::vector v; unsigned int max_child (unsigned int index) const; // precondition: element at index has children // postcondition: index of the larger child has been returned // if there is only 1 child - index of that child has been returned };

#include "heap.template"

#endif // _HEAP_H_

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#ifndef _PRIORITY_QUEUE_H #define _PRIORITY_QUEUE_H

#include "heap.h"

template class priority_queue { public: priority_queue(); // postcondition: empty priority_queue has been created void pop(); // precondition: priority_queue is not emtpy // postcondition: highest priority item has been removed void push (const T& item); // postcondition: item has been inserted bool empty () const; // postcondition: returned whether priority queue is empty unsigned int size() const; // postcondition: returned number of items in the priority queue T top() const; // precondition: priority queue is not empty // postcondition: copy of highest priority item has been returned private: heap h; };

#include "priority_queue.template"

#endif // _PRIORITY_QUEUE_H

The purpose of this lab is to help reinforce heap and priority queue implementations in C++. Specifically, the lab is to problem 2 on page 582 of the text. Note that you will need to implement a heap class (use a vector instead of a dynamic array) and then use the heap class to implement a priority queue. You need to construct a test program to help test the correctness of your code. You need to use heap.h and priority queue.h

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!