I think I have the logic mostly down for this part of the program. However, I am using an implementation of a header file, and in BST::Insert I am handed a const std::string &v. For all I know, it is doing the right job passing it off to InserRecursive, but the compiler is complaining. How can I fix this mess!?
BSTNode * BST::Insert(const std::string & v)
{
if(size==0)
{
size++;
return root = new BSTNode(v);
}
else
InsertRecursive(v, root);
}
BSTNode * BST::InsertRecursive(std::string * str, BSTNode * n)
{
//If the sent string is less than the current node's left value,
//keep traversing. If left node does not exist, add it to the tree
if(*str < n->value)
{
if(n->left==NULL)
{
n->left = new BSTNode(*str);
size++;
return n->left;
}
return InsertRecursive(str, n->left);
}
else if(*str > n->value)
{
if(n->right==NULL)
{
n->right = new BSTNode(*str);
size++;
return n->right;
}
return InsertRecursive(str, n->right);
}
else
return NULL;
}