An abbreviated version of the class BinaryTree
of the text is given below.
template <class T>
class BinaryTreeNode {
friend BinaryTree<T>;
private:
T data;
BinaryTreeNode<T> *LeftChild, // left subtree
*RightChild; // right subtree
};
template<class T>
class BinaryTree {
public:
BinaryTree() {root = 0;};
~BinaryTree(){};
T DeepestElement();
private:
BinaryTreeNode<T> *root; // pointer to root
};
The new member DeepestElement returns
any one of the elements at the maximum level of the binary tree.
- (a)
-
[8]
Write C++ code for the
DeepestElement
member function. You may define and implement new private
member functions as needed.
You may not create or delete any nodes or invoke any binary tree functions
not defined in this problem unless you provide code for these functions.
- (b)
-
[2] What is time complexity of your code as a function
of the number of nodes in the binary tree?