I have a tree class - see bellow - I'd like to traverse and do some processing from a function outside the tree class. In order to traverse the tree I need to set a pointer to the root of the tree. However I can't access the root outside the class since its private.
Is there a way to do this elegantly without using a getter - to retrieve the root address - and without making the root public?
thanks for your help.
template <class Key> class IntervalST
{
private:
Interval<Key> *root;
bool isRed(Interval<Key> *interval);
Interval<Key> *rotateLeft(Interval<Key> *h);
Interval<Key> *rotateRight(Interval<Key> *h);
Interval<Key> *put(Interval<Key> *h,Key lo, Key hi, Key val);
Interval<Key> *moveRedLeft(Interval<Key> *h);
Interval<Key> *moveRedRight(Interval<Key> *h);
Interval<Key> *deleteMin(Interval<Key> *h, Key hi);
Interval<Key> *balance(Interval<Key> *h);
Interval<Key> *remove(Interval<Key> *h, Key lo, Key hi);
Interval<Key> *min(Interval<Key> *h);
Interval<Key> *addDuplicate(Interval<Key> *h, Key hi);
Interval<Key> *removeDuplicate(Interval<Key> *h, Key low, Key hi);
Interval<Key> *getPointerToKey(Key low);
void flipColors(Interval<Key> *h);
void destroy(Interval<Key> *h);
void printTree(Interval<Key> *h, int indent);
Key maxVal(Interval<Key> *h);
int size(Interval<Key> *h);
bool isBST(Interval<Key> *x, Key min, Key max);
inline bool isBST(){return isBST(root,0,0);}
bool isSizeConsistent(Interval<Key> *x);
inline bool isSizeConsistent(){return isSizeConsistent(root);}
bool is23(Interval<Key> *x);
inline bool is23(){return is23(root);}
bool isBalanced();
bool isBalanced(Interval<Key> *x,int black);
int getKeySize(Key low);
int compare(Key a, Key b);
public:
//don't forget to build the constructor
//and overload the =equal operator
IntervalST():root(NULL){};
~IntervalST();
void remove(Key lo, Key hi);
void put(Key lo, Key hi);
inline int size(){return size(root);}
inline bool isEmpty(){return root == NULL;}
void print(int indent = 0);
void check();
};