ok so I am supposed to define a couple of simple recursive functions to operate on a binary search tree. the class definition has been givin to us in two seperate header files the first TreeNode.hpp
class TreeNode {
public:
TreeNode(): left(0), right(0), data(0) {}
TreeNode( int n ): left(0), right(0), data(n) {}
TreeNode local_insert( TreeNode *root, int v );
private:
TreeNode *left, *right;
int data;
};
and the second BinarySearchTree.cpp
class BinSearchTree {
public:
BinSearchTree();
void insert( int v ) { root = local_insert( root, v ); }
bool find( int v );
bool iterFind( int v );
int size();
void inOrderDump();
void levelOrderDump();
int kthSmallest( int k );
void valuesAtLevel( int k );
void iterValuesAtLevel( int k );
int maxDepth();
int iterMaxDepth();
bool hasRootToLeafSum( int sum );
bool areIdentical( BinSearchTree *bst );
BinSearchTree *intersectWith( BinSearchTree *bst );
BinSearchTree *unionWith( BinSearchTree *bst );
BinSearchTree *differenceOf( BinSearchTree *bst );
private:
TreeNode *local_insert( TreeNode *, int );
TreeNode *root;
};
I am also provided with this
TreeNode *BinSearchTree::local_insert( TreeNode *root, int v ) {
if( root == NULL )
return new TreeNode( v );
if( root->value() < v )
root->rightSubtree( local_insert( root->rightSubtree(), v ) );
else
root->leftSubtree( local_insert( root->leftSubtree(), v ) );
return root;
}
the code for the insert function to the binary search tree.
I have two questions the first is what specifically is the underlined line above doing, i have never seen a pointer followed by the scope operator.
and Second is the function find missing any perameters, perhaps maybe a node in the tree, or a pointer to the node in the tree?
ok so the asterisck is accociated with the type that is being returned and not the actual class name?
also what about find sould it need to be passed anything else in order to recursively find one of the data values stored in the nodes of the tree?
Is this a legitamate solution, making two versions of the find function, the one that passes the node is in the private section of the class, should overloaded functions be declared private? is that bad style? If so any hints on a better solution would be appreciated