I've made a binary tree for which I have written a function to remove a word. I change the pointers in such a way that the tree is sorted again correctly but I don't succeed at removing the branch itself.
From one cpp-file.
1 2 3 4 5 6 7 8 9 10
void tree::remove(string word)
{
if (!_root)
return; // If there is no tree, do nothing
branch* dead_branch = _root->remove(word, &_root);
if (dead_branch)
delete dead_branch; // delete the branch if it was extracted.
}
No answer yet, it must have been busy at this forum.
I found the answer on my own, it turns out to be pretty simple but given that this is only the second time that I use this concept it is hard to think about it. I simply had to return after each call and not only when the word was found.