Question
Binary Tree: Write a method void insert( const Entry &x) and the corresponding recursive function to insert an Entry x, passed as a parameter, into
Binary Tree: Write a method void insert(const Entry &x) and the corresponding recursive function to insert an Entry x, 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). An empty tree is considered to have height 0 and a tree with only one node has height 1. You have to write all the methods and functions you need (e.g. you cannot use a height( ) function without writing it here).
template <class Entry>
class Binary_tree {
public:
void insert(const Entry &); // WRITE THIS METHOD
protected:
Binary_node
};
template <class Entry>
struct Binary_node {
// data members:
Entry data;
Binary_node
Binary_node
// constructors:
Binary_node( );
Binary_node(const Entry &x);
};
void insert(const Entry &x) { // write this method
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started