Question
In this assignment you will be using the standard library's vector class to implement a binary heap of signed integers. Your heap should include the following (minimum) data/functionality:
class heap {
private:
std::vector<int> buffer;
public:
heap();
int size();
void insert(int value);
void remove_max();
int max();
void print();
};
You are responsible for testing your heap's functionality, but when I compile against my driver I should be able to say something like:
heap h;
for(int i=0; i<SOME_NUMBER; i++)
h.insert(rand()%100);
while(h.size() > 0) {
cout << h.max() << endl;
h.remove_max();
}
Your program should behave well under similar circumstances.
Bonus:
Turn your class into a templated container. Your templated heap should function well for the C++ primitive types (numeric, char, bool). The templated version of your heap should look something like the following:
template
class heap {
private:
std::vector<T> buffer;
public:
heap();
int size();
void insert(T value);
void remove_max();
T max();
void print();
};
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
#include <cstdlib>#include <cstddef>
#include "Node.h"
#include "BST.h"
using namespace std;
string filter(string input){
string result = "";
int j;
for (j = 0; j < input.length(); j++) {
if (isalpha(input[j])) {
break;
}
}
if (j == input.length()) {
return result;
}
int index1 = 0;
int index2 = 0;
for (int i = 0; i < input.length(); i++) {
if (isalpha(input[i])) {
index1 = i;
break;
}
}
for (int i = input.length() - 1; i >= 0; i--) {
if (isalpha(input[i])) {
index2 = i;
break;
}
}...