I have a binary tree and I am having problems with one function. It is my add function where I add another node to my tree. I use recursion to call it from within the function. I believe I am not using the correct syntax to call the node from within but I cannot understand why this is not working. I think I may be getting confused with how I am calling this.
Here is the function in question.
bool BinarySearchTree::addNode(METADATA **current_node, METADATA *new_node)
{
if(*current_node == NULL)
{
*current_node = new_node;
size++;
return true;
}
else
{
if(strcmp(new_node->key, (*current_node)->key) < 0)
{
return addNode(&((current_node->left), new_node);
}
else if(strcmp(new_node->key, (*current_node)->key) > 0)
{
return addNode(&((*current_node->right), new_node);
}
else
{
delete new_node;
return false;
}
}
}
Both of the recursion calls are getting the following errors
error C2227: left of '->left' must point to class/struct/union/generic type
error C2143: syntax error : missing ')' before ';'
Error 7 error C2660: 'BinarySearchTree::addNode' : function does not take 1 arguments
It seams like it does not like the left but this is defined in my structure
typedef struct METADATA
{
struct METADATA(char *key, char *value)
{
strcpy(this->key, key);
strcpy(this->value, value);
left = NULL;
right = NULL;
}
char key[SIZE_KEY];
char value[SIZE_VALUE];
struct METADATA* left;
struct METADATA* right;
}METADATA;
Any help in understanding why my recursion call is not working is appreciated.