C++ Question
Can someone add code to this code that removes a value from thetree.
Example tree->delete(18)
#include
using namespace std;
struct node{
int value;
node *left;
node *right;
};
class btree{
public:
btree();
~btree();
void insert(int key);
node *search(int key);
void destroy_tree();
void inorder_print();
void postorder_print();
void preorder_print();
private:
void destroy_tree(node *leaf);
void insert(int key, node *leaf);
node *search(int key, node *leaf);
void inorder_print(node *leaf);
void postorder_print(node *leaf);
void preorder_print(node *leaf);
node *root;
};
btree::btree(){
root = NULL;
}
btree::~btree(){
destroy_tree();
}
void btree::destroy_tree(node *leaf){
if(leaf != NULL){
destroy_tree(leaf->left);
destroy_tree(leaf->right);
delete leaf;
}
}
void btree::insert(int key, node *leaf){
if(key < leaf->value){
if(leaf->left != NULL){
insert(key,leaf->left);
}else{