Question: Please help me implement some functions about heap using BST, C++, Thanks! And here's the test need to pass. // examheap.cpp #include heap.h #include #include

Please help me implement some functions about heap using BST, C++, Thanks!

Please help me implement some functions about heap using BST, C++, Thanks!And here's the test need to pass. // examheap.cpp #include "heap.h" #include

And here's the test need to pass.

// examheap.cpp

#include "heap.h"

#include

#include

#include

#include

#include

#include

using namespace std;

int main(int argc, char *argv[]) {

if (argc

cout

return 1;

}

int t = atoi(argv[1]);

std::priority_queue, std::greater> data;

Heap h;

int numvals = 3;

if (t == 1) {

cout

int sum = 0, count = 0;

Heap h;

srand(time(0));

int arand = rand() % 1000;

int brand = arand -10;

h.push(arand);

assert(h.top()==arand);

h.pop();

assert(h.empty());

h.push(arand);

h.push(brand);

assert(h.top()==brand);

h.pop();

h.pop();

assert(h.empty());

h.push(brand);

h.push(arand);

assert(!h.empty());

assert(h.top()==brand);

cout

return 0;

}

if (t == 2) {

cout

numvals = 3;

}

if (t == 3) {

cout

numvals = 4;

}

if (t == 4){

cout

numvals = 200;

}

if (t == 5){

cout

numvals = 20000;

}

for (int i=0; i

int arand = rand() % 2000;

data.push(arand);

h.push(arand);

}

while(!data.empty()){

assert(!h.empty());

assert(data.top()==h.top());

data.pop();

h.pop();

}

cout

return 0;

}

o heap.cpp- Edited heap.cpp No Selection 1 // heap.cpp 4 #include "heap.h" #include 6 using std::cout; 8 // Pushes a value into the heap, then ensures 9 // the heap is correctly arranged 10 void Heap::push (int value) 12 13 14 // Pops the minimum value off the heap 15 // (but does not return it), then ensures 16 // the heap is correctly arranged 17 void Heap::pop) 18 19 20 21 // Returns the minimum element in the heap 22 int Heap::top) 23 24 25 26 // Returns true if the heap is empty, false otherwise 27 bool Heap: :empty) 28 29 30 31 return 0 return true

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!