我正在寻找我的AVL树的一些帮助,这是我作为学校相关项目的工作。我对自己做错了很遗憾。
我的插入函数是递归插入的,节点没有连接在一起。我知道这是次要的,但我觉得我已经测试了大多数途径
我的插入功能如下
void Tree::Insert(int & entry, Node * nextEntry)
{
//Temp node declared for use in the function
Node * temp = nullptr;
//Check if the value is equal
if (nextEntry != nullptr && nextEntry->value == entry)
{
if (entry == nextEntry->value)
{
cout << "\n\t DUPLICATE DATA FOUND\n";
}
}
//Going to the left side
if (nextEntry != nullptr && entry < nextEntry->value )
{
temp = nextEntry->leftChild;
nextEntry->balanceFactor++;
Insert(entry, temp);
}
//Check to make sure that the root isnt empty
//Going to the right side
if (nextEntry != nullptr && entry > nextEntry->value )
{
temp = nextEntry->rightChild;
nextEntry->balanceFactor--;
Insert(entry, temp);
}
if (nextEntry == nullptr)
{
nextEntry = new Node(entry);
}
if (nextEntry->balanceFactor >= balanceExceededLeft || nextEntry->balanceFactor <= balanceExceededRight)
{
BalanceTree(nextEntry);
}
}
感谢你的时间,非常感谢任何帮助