I want to save the data found within my tree but I am not sure how to do this. I was thinking that my printInOrder() function could be changed to be generic and return the data to the calling function which is from another class. Can anyone help?
Code:
template <class T>
struct AVLnode
{
friend class AVLtree<T>;
T info;
int balance;
AVLnode<T> *right;
AVLnode<T> *left;
AVLnode () {right = left = NULL;}
};
Code:
template <class T>
class AVLtree
{
public:
AVLnode<T> *tree;
AVLtree () {tree=NULL; fail=false; srchResult=0;};
~AVLtree () {clear(tree);};
void insertData (const T &data);
void printAVLtree () {printInOrder(tree);};
T searchTree (T& data) {return (srchTreeHelper(tree, data));};
protected:
void insertHelper (AVLnode<T> *&root, AVLnode<T> *node, bool &higher, T data);
void rightBalance (AVLnode<T> *&root, bool &higher);
void leftBalance (AVLnode<T> *&root, bool &higher);
AVLnode<T>* rotateRight (AVLnode<T> *root);
AVLnode<T>* rotateLeft (AVLnode<T> *root);
void clear (AVLnode<T> *tree);
void printInOrder (AVLnode<T> *root);
T srchTreeHelper (AVLnode<T> *treeRoot, T& data);
};
Code:
template <class T>
void AVLtree<T>::printInOrder (AVLnode<T> *root)
{
if (root)
{
printInOrder (root->left);
cout <<root->info.key; <-- Not Generic
cout <<root->info.ID; <-- Not Generic
cout <<root->info.txt; <-- Not Generic
printInOrder (root->right);
}
}