I am trying to figure out how to remove a node from a binary search tree, I understand that it is different for each node whether it is a leaf, has one child or two children. So as of now my function is nothing more than:
bool BinSTree::remove_root(treeNode*& node) {
if(node -> left == NULL && node -> right == NULL) {
}
elseif(node -> left != NULL && node -> right != NULL) {
}
else {
}
}
I am having a very hard time trying to comprehend the logic, for instance I know for all of them I need to be able to find the parent node to the node being deleted, which is where I am left clueless and any help would be much appreciated!
This sounds like homework. You might find this article on binary tree rotation to be helpful. In addition to give you some hints on how to handle some interesting cases, that article will also show you how you might diagram the problem out for yourself.
Deleting from a tree is an interesting case, and I remember puzzling over it when I wrote my own AVL tree implementation in C in the late 80s.