Trees can be traversed in many ways, mostly used are:
Following breakdown of steps would help:
1. Use one of the tree traversal methods and check if the current node matches with the node you are searching for.
2. If found, delete the node and stop traversing further
3. If the tree is completely traversed and none of the node matched then display Node not found.
bool checkIfNodeExists(struct Node* node, int key)
if (node == NULL)
if (node->data == key)
bool resultLeft = checkIfNodeExists(node->left, key);
bool resultRight = checkIfNodeExists(node->right, key);
Quote:void delete_tree(binarytree *tree, int val)
Your method looks way too complicated. You should extract the common logics out of it.
This method should pass the node you are searching to delete to the
method and based on the result, take an action of deleting or messaging (if not found). This would make it easier for you to see where you might be missing something and need to make change.