我正在为我的 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);
}
}
任何帮助将不胜感激,感谢您的时间