
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;
}
Gentoo binário em 2026: UEFI, LUKS, Btrfs e Systemd
Trabalhando Nativamente com Logs no Linux
Jogando Daikatana (Steam) com Patch 1.3 via Luxtorpeda no Linux
LazyDocker – Interface de Usuário em Tempo Real para o Docker
Usando dracut e dispensando genkernel no Gentoo + LUKS + Btrfs
Curso GRÁTIS: OCS Inventory NG - Do Deploy ao Hardening com foco em Segurança da Informação!
Instalando fontes via script no Nautilus Scripts no Gnome do Debian 13
Removere linux-image-6... [RESOLVIDO] (2)
Quando vocês pararam de testar distros? (19)
O que houve com slackware ??? (6)









