Algorithm_fromBilibili
Algorithm_fromBilibili copied to clipboard
Binary Search Tree
二叉搜索树的插入及生成算法存在问题
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;
}
}