node *recherche_arbre(node **tree, int val) { if ((*tree) == NULL) return (NULL); if (val < (*tree)->data) recherche_arbre(&((*tree)->left), val); else if (val > (*tree)->data) recherche_arbre(&((*tree)->right), val); else if (val == (*tree)->data) return (*tree); return (*tree); }
/* * exécute la recherche */ void execute_recherche() { //long j = 0; char *nom_recherche; T3 = (long*) calloc(k, sizeof(long)); switch (choixTest) { case 1: nom_recherche = "recherche sequentielle"; recherche_sequentielle(T1, grandeur_tableau, Rang, Desordre, T2, k); break; case 2: nom_recherche = "recherche binaire"; recherche_binaire(T1, grandeur_tableau, Rang, Desordre, T2, k); break; case 3: nom_recherche = "table de hachage"; recherche_hachage(T1, grandeur_tableau, Rang, Desordre, T2, k); break; case 4: nom_recherche = "arbre de recherche"; recherche_arbre(T1, grandeur_tableau, Rang, Desordre, T2, k); break; case 5: nom_recherche = "recherche optimisée"; recherche_optimisee(T1, grandeur_tableau, Rang, Desordre, T2, k); break; default: break; } EcritureTableaux(nom_recherche, tri, stdout); EcritureTableaux(nom_recherche, tri, NULL); }
int main(int ac, char **av) { node *root; //node *tmp; root = NULL; //tmp = NULL; node *opti; opti = NULL; if (ac == 1) { ft_putstr("Erreur : manque les parametres"); return (0); } int i; i = 1; while (i < ac) { insert(&root, ft_atoi(av[i])); i++; } //organize(&root); affiche_arbre_rec(root); ft_putchar('\n'); opti_arbre_rec(root, &opti); affiche_arbre_rec(opti); ft_putstr("\nresultat de la recherche : "); ft_putnbr(recherche_arbre(&root, 85)->id); //affiche_arbre_rec(root, &opti); /* Search node into tree */ /* tmp = search(&root, 9); if (tmp) printf("\nSearched node = %d\n", tmp->data); else printf("\nData Not found in tree.\n"); */ /* Deleting all nodes of tree */ deltree(root); }