Hello, friends. I am having a little problem with a c++ tree... When i try to delete a node, and there is just one node in the tree (so I must delete the root), the program does not work ("Segmentation Fault" message, compiling on Linux). Here is my code, and below is the logic that I tried to follow.. can you help, me please? Thank you very much!
*aux is the node that I must delete, and aux_prev is the previous node
if (the node don't have sons)
{
if (is not the root)
{
if (the node is in the right of the previous node)
{
aux_ant->right = NULL;
delete aux;
}
else //the node is in the left of the previous node
{
aux_ant->left = NULL;
delete aux;
}
}
else //if is the root
{
tree.root = NULL; //the root ponts to NULL
delete aux; //delete the node
}
}
Pergunta
Murilo Marchiori
Hello, friends. I am having a little problem with a c++ tree... When i try to delete a node, and there is just one node in the tree (so I must delete the root), the program does not work ("Segmentation Fault" message, compiling on Linux). Here is my code, and below is the logic that I tried to follow.. can you help, me please? Thank you very much!
*aux is the node that I must delete, and aux_prev is the previous node
if(aux->right == NULL && aux->left == NULL) { if(aux_prev != NULL) { if(aux_prev->right == aux) { aux_prev->right = NULL; delete aux; } else { aux_prev->left = NULL; delete aux; } } else { tree.root = NULL; delete aux; } }if (the node don't have sons) { if (is not the root) { if (the node is in the right of the previous node) { aux_ant->right = NULL; delete aux; } else //the node is in the left of the previous node { aux_ant->left = NULL; delete aux; } } else //if is the root { tree.root = NULL; //the root ponts to NULL delete aux; //delete the node } }Link para o comentário
Compartilhar em outros sites
0 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.