Create a class template for the binary tree class described as follows:
class Binary_node {
public:
Entry data;
Binary_node* leftptr;
Binary_node* rightptr;
// Public Operations
Binary_node() { leftptr = rightptr = NULL;}
Binary_node(const Entry &x) {
leftptr = rightptr = NULL;
data = x.data;
}
};
class Binary_tree {
protected:
Binary_node* root;
public:
// Public Operations
Binary_tree() { root = NULL;}
bool empty() const { return root == NULL;}
void inorder(void (*visit)( Entry &));
void preorder(void (*visit)( Entry &));
void postorder(void (*visit)( Entry &));
int size( ) const; // to count all the nodes of a linked binary tree
void clear( ); // dispose all nodes
int height( ) const;
void insert(const Entry &);
Binary_tree (const Binary tree &original);
Binary_tree & operator = (const Binary_tree &original);
~Binary_tree( ); // use clear()
private:
void recursive_inorder(Binary_node * sub_root,
void(*visit)( Entry &x));
};
void Binary_tree :: inorder(void (*visit)( Entry &))
{
recursive_inorder(root, visit);
}
Use the following specification to implement the Binary_tree() template class.
1. Write a method and the corresponding recursive function to count all the nodes of a linked binary tree. size()
2. Write a method and the corresponding recursive function to find the height of a linked binary tree, where an empty tree is considered to have height 0 and a tree with only one node has height 1.
3. Write a method and the corresponding recursive function to insert an Entry, passed as a parameter, into a linked binary tree. If the root is empty, the new entry should be inserted into the root, otherwise it should be inserted into the shorter of the two subtrees of the root(or into the left subtree if both subtrees have the same height).
void insert(const Entry &);جزاكم الله خير حلو لي هالبرنامج ضرووري قبل الاربعاء وفكوا عني ازمه
حاولت فيه لكن والله ماقدرت
وجزاكم الله ألف خير
