Question: Implement the following MySet class as a templated Binary Search Tree. You may add helper functions but may not change the function declarations. (C++) #include
Implement the following MySet class as a templated Binary Search Tree. You may add helper functions but may not change the function declarations. (C++)
#include
#include
//Node node for Set
template
struct SetNode
{ T data;
SetNode* left;
SetNode* right;
SetNode(const T& value);
};
//Set based on a BST
template
class MySet
{ private:
SetNode* root;
public:
//Construct empty set
MySet();
//Copy constructor
MySet(const MySet& other);
//Assignment operator - implement if needed
MySet& operator=(const MySet & other);
//Destructor
~MySet();
//get number of items contained
int size() const;
//get depth of underlying tree
int depth() const;
//Add item to set
// Do not add duplicates of existing items - ignore any duplicate add
void add(const T& item);
//Check if item is in the set
bool contains(const T& item) const;
//Remove given item from the set if it exists
void remove(const T& item);
//returns the smallest item from the set (does not remove it)
T getSmallest() const;
//removes the largest item from the set and returns it
T removeLargest();
//Generates a new set containing all the items that are in either
// this set or another set
// intersections of {A, B, C, D} and {B, D, F} would be {A, B, C, D, F} // Both original sets are left unmodified
MySetunionWith(const MySet & other) const;
//Generates a new set containing all the items that are in both
// this set and another set
// intersections of {A, B, C, D} and {B, D, F} would be {B, D} // Both original sets are left unmodified
MySetintersectionWith(const MySet & other) const;
//Returns a vector of items in the set that are >= start and < end
std::vectorgetRange(const T& startValue, const T& endValue) const;
Node implementation:
template
Set Implementation:
//YOUR_CODE_HERE//
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
