Question: #ifndef SET _ TYPE #define SET _ TYPE #include #include #include #include using namespace std; class IteratorOutOfBounds { public: string Msg ( ) { return
#ifndef SETTYPE
#define SETTYPE
#include
#include
#include
#include
using namespace std;
class IteratorOutOfBounds
public:
string Msg
return "Iterator is out of bounds. Nothing left to iterate over.";
;
const int DEFAULTBUCKETS ;
const double DEFAULTLOADFACTOR ;
template
class SetType
public:
Constructors
SetType;
explicit SetTypeint numBucks;
SetTypeSetType& other;
~SetType;
void AddT elem;
void RemoveT elem;
bool ContainsT elem;
void MakeEmpty;
int Size const
return numElems;
double LoadFactor const;
void SetMaxLoaddouble max;
void Rehashint newNumBuckets;
SetType operatorT elem; Add
SetType operatorT elem; Remove
SetType operatorSetType& otherSet; Union
SetType operatorSetType& otherSet; Difference
SetType operatorSetType& otherSet; Intersection
SetType& operatorSetType const& otherSet; Assignment does deep copy
void ResetIterator; Reset iterator
T GetNextItem;
private:
forwardlist buckets; An array of forwardlist's
each index is a forwardlist
int numBuckets; total number of buckets
int GetHashIndexconst T& key; Gets the hash index given the elem
int numElems; total number of elements
double maxLoad; load factor of the Set
This function is used by the
copy constructor and the assignment operator.
void copySetconst SetType& otherSet;
Iterator variables
int currBucket; What bucket is the iterator on
int iterCount; What element are we on
mutable typename forwardlist::iterator bucketIter; The iterator of the current bucket
Any other private functions and variables you wantneed
;
#include "SetType.cpp
#endif
Settype.cpp
#include
#include
#include "SetType.h
using namespace std;
template
SetType::SetType
Create an array of forwardlists and initially set to an empty forwardlist
buckets new forwardlistDEFAULTBUCKETS;
numBuckets DEFAULTBUCKETS;
numElems ;
maxLoad DEFAULTLOADFACTOR;
currBucket ;
iterCount ;
Constructor that takes a number of buckets
template
SetType::SetTypeint numBucks
numBuckets numBucks;
buckets new forwardlistnumBuckets; Allocate new array of buckets
numElems ; No elements in the new set initially
maxLoad DEFAULTLOADFACTOR; Default load factor
currBucket ; Reset iterator
iterCount ;
template
SetType::SetTypeSetType &otherSet
copySetotherSet;
template
SetType::~SetType
delete buckets;
template
SetType SetType::operatorT elem
SetType result;
Your code here
return result;
template
SetType SetType::operatorT elem
SetType result;
Your code here
return result;
template
SetType SetType::operatorSetType& otherSet
SetType result;
Your code here
return result;
template
SetType SetType::operatorSetType& otherSet
SetType result;
Your code here
return result;
template
SetType SetType::operatorSetType& otherSet
SetType result;
Your code here
return result;
template
T SetType::GetNextItem
Returns the current item and then move to the next item
T item;
Your code here
return item;
template
int SetType::GetHashIndexconst T& key
This is done... No touching!
unorderedmap mapper;
typename unorderedmap::hasher hashFunction mapper.hashfunction;
return staticcasthashFunctionkey numBuckets;
template
void SetType::SetMaxLoaddouble max
This function is done
if max
maxLoad ;
else
maxLoad max;
template
SetType& SetType::operatorSetType const &other
Your code here
return this;
template
void SetType::Rehashint newNumBuckets
SetType rehashedSetnewNumBuckets;
Your code here
this rehashedSet;
can you help me implement this based on the header above?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
