hi stavo scrivendo un BST e scrisse seguente funzione per l'aggiunta del bambino.
void addChild(T value)
{
temp = root;
while(0 != temp)
{
temp1 = temp;
if(value > temp->getValue())
temp = temp->getRightChild();
else
temp = temp->getLeftChild();
}
if(temp1->getValue() > value)
{
temp1->setRightChild(new Child(value));
}
else
{
temp1->setLeftChild(new Child(value));
}
}
Io sto dando 23 12 122 1 121 15 come input. Radice è il nodo 23 che sto creando nel costruttore della classe.
Problema: quando sto facendo attraversamento di alberi sto ottenendo solo il 23 e il 15 come uscita. Domanda : Che cosa sto facendo di sbagliato in questa funzione?













