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;
}
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Descritores de Arquivos e Swappiness
Solução rápida para o problema do Network Manager conectar mas não navegar
Como instalar no Linux Jogos da Steam só para Windows
Instalando o Team Viewer no Debian Trixie - problema no Policykit
Interface Gráfica no Linux Mint 22.1. (3)
Ubuntu 25.04 não instala. (11)