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;
		}

Well, the first error is this, the declaration of BST::InsertRecursive: BSTNode * BST::InsertRecursive(std::string * str, BSTNode * n) in that you are calling it with a const string& (reference), yet the function is defined to tak a non-const string pointer... No go. Realize that C++ is VERY strict in type usage. Also, I don't know if the root argument passed for the second argument, defined as a BSTNode* is a pointer or something else.

The root variable is a pointer. I've changed things around, and it looks like it will work based on your suggestions - thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.