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 on
Just use a destructors. It sounds like your problem is that you were trying to call the destructors directly, but the language handles this for you. They're called either when you leave a stack allocated object's scope, or when you delete an object.
All you should need is this:
~BinSearchTree() {
delete left;
delete right;
}
delete
will call their destructors.
Note: It's perfectly safe to delete NULL
, it has no effect.