AVA2 Banco de Dados Ricardo Dos Anjos
AVA2 Banco de Dados Ricardo Dos Anjos
AVA2 Banco de Dados Ricardo Dos Anjos
AVA2
Niterói - RJ
2023
Segue abaixo o programa para manipular uma arvore binária como solicitado pela
empresa.
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* left;
struct Node* right;
};
return root;
}
if (root->left == NULL) {
struct Node* temp = root->right;
free(root);
return temp;
} else if (root->right == NULL) {
struct Node* temp = root->left;
free(root);
return temp;
}
root->data = temp->data;
return root;
}
int main() {
struct Node* root = NULL;
int choice, value;
do {
// Menu de opções
printf("\n* * * MENU DE OPCOES * * *\n");
printf("1. Incluir no\n");
printf("2. Remover no\n");
printf("3. Buscar pre-ordem\n");
printf("4. Buscar em ordem\n");
printf("5. Buscar pos-ordem\n");
printf("0. Encerrar\n");
printf("Opcao: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Digite o valor a ser incluido: ");
scanf("%d", &value);
root = insertNode(root, value);
break;
case 2:
printf("Digite o valor a ser removido: ");
scanf("%d", &value);
root = deleteNode(root, value);
break;
case 3:
printf("Busca pre-ordem: ");
preOrderTraversal(root);
printf("\n");
break;
case 4:
printf("Busca em ordem: ");
inOrderTraversal(root);
printf("\n");
break;
case 5:
printf("Busca pos-ordem: ");
postOrderTraversal(root);
printf("\n");
break;
case 0:
printf("Encerrando o programa. \n");
break;
default:
printf("Opcao invalida. Tente novamente.\n");
}
} while (choice != 0);
return 0;
}
Referência:
BORIN, Vinicius Pozzobon. Estrutura de dados. 1. ed. São Paulo: Contentus, 2020.
Dados e Projeto Usando C++. São Paulo: Grupo GEN, 2008. E-book. ISBN 978-85-