Algorithm_fromBilibili icon indicating copy to clipboard operation
Algorithm_fromBilibili copied to clipboard

Binary Search Tree

Open Weiyi-Huang opened this issue 1 year ago • 0 comments

二叉搜索树的插入及生成算法存在问题

void InsertBSTree(BSTree &T, const ElemType &e)

// 原代码
if (T == nullptr)
{
    T = new BSNode;
    T->data = e;
}
// 此处的树左右孩子应置为空指针,更改后的代码
if (!T)
{
    T = new BSTNode;
    T->data = e;
    T->lchild = nullptr;
    T->rchild = nullptr;
}

void CreatBSTree(BSTree &T)

// 原代码
while(cin>>input.key)
{
    vec.push_back(input);
}
// 此处应加入输入终止条件(如回车键终止输入),更改后的代码
while (cin >> input.key)
{
    vec.push_back(input);
    if(cin.get() == '\n') 
    {
        break;
    }
}

Weiyi-Huang avatar Feb 10 '24 07:02 Weiyi-Huang