I've created a binary search tree, each node of my binary tree is setup in a struct containing the key, and a pointer to the left and right nodes.
In my copy constructor for this binary search tree, I call a helper method to recurs through the tree that looks like so:
Node* BinaryTree::copyHelper(const Node* other)
{
if(other == NULL)
{
return NULL; // If there's no Node to copy, return NULL.
}
Node* newNode = new Node;
if(newNode)
{
newNode->name = other->name;
newNode->left = copyHelper(other->left);
newNode->right = copyHelper(other->right);
}
return newNode;
}
My error mentioned in the title is on the left and right pointers in the final if statement above.
If someone could tell me how to remove it, that would be appreciated.