
Enviado em 23/04/2022 - 18:38h
Olá, estou tentando fazer um algoritmo simples de árvore binária em C, mas a função para deletar um nó simplesmente não faz efeito algum.void delNode(Node *root)
{
Node *leaf, **nroot;
int found = 0, target;
printf("\nNode to be removed: ");
scanf("%d", &target);
printf("\n");
while (root != NULL){
if (root->code == target){
nroot = &root;
found = 1;
break;
}
if (target < root->code) root = root->left;
else root = root->right;
}
if (!found){
printf("Node not found.");
return;
}
if ((*nroot)->left == NULL && (*nroot)->right == NULL) *nroot = NULL;
else if ((*nroot)->left != NULL) *nroot = (*nroot)->left;
else if ((*nroot)->right != NULL) *nroot = (*nroot)->right;
else {
leaf = findClosest(*nroot);
*nroot = leaf;
leaf = NULL;
free(leaf);
}
if (*nroot == NULL) free(*nroot);
return;
}
int main()
{
Node *root = NULL;
for (int i=0; i<10; i++){
if (root == NULL) root = insNode(root, createNode());
else insNode(root, createNode());
}
printf("\n");
prntTree(root);
printf("\n");
delNode(root);
prntTree(root);
return 0;
}
XFCE - quase um Gnome ou Plasma mas muito mais leve
LXQT - funcional para máquinas pererecas e usuários menos exigentes
Samba 4 AD-DC 2026: Como instalar e configurar um Active Directory (via APT-GET)
[Resolvido] Sumiço de redes e micro quedas no iwd/iwgtk (Realtek rtw88)
Como Configurar DNS Reverso (PTR) em Ambientes Linux e Microsoft
Preparando o Ambiente para Administrar o Samba 4 a partir do Windows com RSAT









