Using C++, Implement ReheapDown (whole program), then use thebelow example to print the new output. Analyze the time complexity.Here is the example:
Here is some example code to get you started:
void HeapType::ReheapDown(int root, into bottom) {
int maxChild, leftChild, rightChild;
leftChild= root*2+1;
rightChild= root*2+2;
if(leftChild<=bottom)
{
if(leftChild==bottom)
maxChild=leftChild;
else
{
if(elements[leftChild]<=elements[rightChild])
maxChild=rightChild;
else
maxChild=leftChild;
}
if(elements[root] {
swap(elements[root], elements[maxChild]);
ReheapDown(maxChild, bottom)
}
}
}
class HeapType
{
private:
int* maxHeap;
int i;
public:
int length;
Nodetype elements[20];
HeapType();
void Enqueue(Nodetype);
void Insert(int key);
void Dequeue(Nodetype&);
void ReheapDown(int root, int bottom);
void ReheapUp(int root, int bottom);
void Swap(int A, int);
void Max_Heapify(Nodetype elements[], int length);
int getMax();
};
Solution