void DeleteNode(struct node*& node) {
if (node->left == NULL) {
struct node* temp = node;
node = node->right;
delete temp;
} else if (node->right == NULL) {
struct node* temp = node;
node = node->left;
delete temp;
} else {
// In-Order predecessor(right most child of left subtree)
// Node has two children - get max of left subtree
struct node** temp = &(node->left); // get left node of the
original node
// find the right most child of the subtree of the left node
while ((*temp)->right != NULL) {
temp = &((*temp)->right);
}
// copy the value from the right most child of left subtree to
the original node
node->value = (*temp)->value;
// then delete the right most child of left subtree since it's
value is
// now in the original node
DeleteNode(*temp);
}
}