Without using a treeiterator create a new method called


Project: Working With Binary Search Trees

Complete the following exercises using the cs20::BST class presented in class.

1. Without using a TreeIterator, create a new method called total that takes an no arguments and determines that the sum of all the elements stored in the BinarySearchTree.  If the root of the tree is nullptr, then your method should throw an InvalidTreeArgument exception.  The prototype of this method should be:

int BST< Object >::total( ) const throw( InvalidTreeArgument );

Because the method has been marked const, your implementation will not be able to change any of the data members found in the BinarySearchTree.  Instead, you should use recursion to walk all the nodes in the tree and return the total seen so far in the recursive stack.

Create a test driver that exercises this new feature, prints the tree and the results of this new operation.

2. Without using a TreeIterator, create a new method called isMatchingTree that takes an BST parameter and determines if this tree has the exact same matching structure as the passed parameter.  In other words, the exact same data values need to be found in both trees in the exact same structural arrangement.  If the root of the tree is nullptr, your method should throw an InvalidTreeArgument exception.  The prototype for this method should be:

bool BST< Object >::isMatchingTree( BST< Object >otherTree ) const throw( InvalidTreeArgument );

Because the method has been marked const, your implementation will not be able to change any of the data members found in the BinarySearchTree.  Instead, you should use recursion to walk all the nodes in the tree and verify that the same matching element value is found in each node.

Create a test driver that exercises this new feature, prints the tree and the results of this new operation.

Attachment:- Assignment.zip

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Without using a treeiterator create a new method called
Reference No:- TGS01664040

Expected delivery within 24 Hours