Searching for a node in a BST
def search(bst, value):
if bst is None or bst.get_data() == value:
return bst
if bst.get_data() < value:
return search(bst.get_right(), value)
return search(bst.get_left(), value)
Searching for a node in a BST
def search(bst, value):
if bst is None or bst.get_data() == value:
return bst
if bst.get_data() < value:
return search(bst.get_right(), value)
return search(bst.get_left(), value)
insert binary search tree
void BSNode::insert(std::string value) {
if (this->_data == value) {
_count++;
return;
}
if (this->_data > value) {
if (this->getLeft() == nullptr) {
this->_left = new BSNode(value);
}
this->getLeft()->insert(value);
return;
}
if (this->getRight() == nullptr) {
this->_right = new BSNode(value);
return;
}
this->getRight()->insert(value);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us