📜  插入二叉搜索树 - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:49.400000             🧑  作者: Mango

代码示例1
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);
}