Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Microsoft Outlook 2023

Authors: James Holler

1st Edition

B0BP9P1VWJ, 979-8367217322

More Books

Students also viewed these Databases questions

Question

u = 5 j , v = 6 i Find the angle between the vectors.

Answered: 1 week ago