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 data;

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

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!