Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- node* delete(node* tree, int x)
- {
- if (tree == NULL)
- {
- return tree;
- }
- if (x < tree->data)
- //delete node from left subtree
- tree->left = delete(tree->left, x);
- else if (x > tree->data)
- //delete node from right subtree
- tree->right = delete(tree->right, x);
- else
- {
- if (tree->left == NULL)
- {
- node* temp = tree->right;
- free(tree);
- return temp;
- }
- else if (tree->right == NULL)
- {
- node* temp = tree->left;
- free(tree);
- return temp;
- }
- node* temp = min_value_node(tree->right);
- tree->data = temp->data;
- tree->right = delete(tree->right, temp->data);
- }
- return tree;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement