Эта функция вставки не работает, показанная здесь с моим отладочным кодом и конструктором узла. После доступа к root, когда он достигает второго прохода через do l oop, он отображает ptr-> entry так же, как newEntry, и я не знаю почему. Я просто переделал код, который работал раньше ...
BTreeNode::BTreeNode(double newEntry)
{
entry = newEntry;
lChild = NULL;
rChild = NULL;
}
void BSTree::insert(double newEntry)
{
BTreeNode* tmp = new BTreeNode(newEntry);
if (root == NULL)
{
root = tmp;
cout << "New root!\n";
return;
}
BTreeNode* ptr = root;
do
{
cout << newEntry << ' ' << ptr->entry << endl;
if (newEntry > ptr->entry)
{
if (ptr->rChild == NULL)
{
ptr->rChild = tmp;
cout << "New node to the right!\n";
delete tmp;
return;
}
else
{
ptr = ptr->rChild;
cout << "Passing through the right.\n";
}
}
else
{
if (ptr->lChild == NULL)
{
ptr->lChild = tmp;
cout << "New node to the left!\n";
delete tmp;
return;
}
else
{
ptr = ptr->lChild;
cout << "Passing through the left.\n";
}
}
cout << "Looping though.\n";
} while (true);
}