I'm implementing remove method for binary search tree in C++. In one of cases I am sure that tree node has only one child: node->left or node->right and I need to modify it's parent to point to that child. As I mentioned before one of node->left and node->right are NULL. Here's a snippet:
} else { // One children
if (node->parent->left == node) {
node->parent->left = node->left | node->right;
node->parent->left->parent = node->parent;
} else {
node->parent->right = node->left | node->right;
node->parent->right->parent = node->parent;
}
}
Unfortunatelly, compiler returns an error. I know that it's maybe not the elegant one but I was just curious how to do it.