Working on implementing my own BST in C++ for the experience of dealing with such structures.
I've had trouble implementing a destructor. I found in my studies, that one can't really have a recursive destructor (due to a flag that doesn't allow the destructor to be called on the same object after having been called), but I'm not really sure of any other way to successfully clean up all the nodes in the tree.
To compensate, I've created a helper function - however this throws an unresolved external error on the 'delete n' line. Any tips?
Code:
void BinSearchTree::Clear(tNode* n)
{
if (n->left != NULL)
Clear(n->left);
if (n->right != NULL)
Clear(n->right);
delete n;
n = NULL;
size--;
}