Question
Implement in C++, please comment on your code. //Some heaps separate value from their priority to manage items. This helper class allows us to directly
Implement in C++, please comment on your code.
//Some heaps separate value from their priority to manage items. This helper class allows us to directly compare items by comparing their priorities.
NOTE: Only implement enqueue and reheapUp, TWO functions :)
Implement void enqueue(HeapEntryHelper x) and its void reheapUp(int currentIndex) helper method to work on a vector that places the root at index 0 instead. Based on the given code.
#include
#include
#include
using namespace std;
class HeapEntryHelper {
//Some heaps separate value from their priority to manage items.
//This helper class allows us to directly compare items by comparing their priorities.
public:
//Fields, the fields are public. This class is effectively a pair.
string data;
int dataPriority;
//Constructor
HeapEntry(string d, int p) {
data = d;
dataPriority = p;
} };
class MaxHeap {
private:
//Fields
vector
int size{ 0 }; //Number of items stored
int capacity{ 0 }; //Number of items that can be stored without expanding
void reheapUp(int currentIndex) {} //Private helper methods
public:
//Constructor
MaxHeap() {data.push_back(HeapEntry("", 0));} //Black entry into index 0 in the vector, place root at index 1
void enqueue(HeapEntryHelper x) {} //enqueue function
};
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