hi
i was writing a class template for a binary tree,here's my code:
template<class T>
class binary_tree{
private:
class node{
public:
T key;
node *right;
node *left;
node(){}; //COSTRUTTORE
node(T n){key=n;right=NULL;left=NULL;} //COSTRUTTORE
};
node *root;
public:
binary_tree(){root=NULL;}
void insert(T);
void print_inorder(node<T> *);
void print();
};
i have problem in the print_inorder:
template<class T>
void binary_tree<T>::print_inorder(node<T> *ptr)
{
if(ptr!=NULL)
{
if(ptr->left)
print_inorder(ptr->left);
cout<<" "<<ptr->key<<" ";
if(ptr->right)
print_inorder(ptr->right);
}
else return;
}
can somebody help me out?
thanks
Where do you get an error?
P.S. Here is the ordinary function that I use:
1 2 3 4 5 6 7 8
|
template<class T>
void binary_tree<T>::print_inorder(node<T> *ptr)
{
if(ptr == NULL) return;
print_inordered(ptr->left);
cout << ptr->key << " ";
print_inordered(ptr->right);
}
|
Last edited on