void remove(const KeyType& key, NodePtr parent) { if(root != nullptr) { if(root->key == key) { removeRootMatch(); } else { if(key < parent->key && parent->left != nullptr) { if(parent->left->key == key) { removeMatch(parent,parent->left,true); } else { remove(key,parent->left); } } else if(key > parent->key & parent->right != nullptr) { if(parent->right->key == key) { removeMatch(parent,parent->right,false); } else { remove(key,parent->right); } } else { std::cout << "Key " << key << "not found" << std::endl; } } } else { std::cout << "The tree is empty" << std::endl; } }
void Trees::removeNodep(int data, Node* parent) { //If the tree was NOT Empty if(root != NULL) { //If the data was found / delete if(root->data == data) { removeRootMatch(); } //If the data was not found else { //Left child (less than n) if(data < parent->data && parent->left != NULL) { parent->left->data == data ? removeMatch(parent, parent->left, true): removeNodep(data, parent->left); } //Right child (greater than n) else if(data > parent->data && parent->right != NULL) { parent->right->data == data ? removeMatch(parent, parent->right, false): removeNodep(data, parent->right); } else { cout << "The data " << data << " was not found in the current tree." << endl; } } } //If the tree is empty else { cout << "The tree is empty." << endl; } }