salut,
j'essaye de faire un arbre de dico mais ça bloque et ça veut pas se compiler
voila ce que j'ai fais
[code]
#include <cstdlib>
#include <iostream>
typedef struct s_arbre
{
struct s_arbre *droite, *gauche;
char *info;
} t_arbre;
//Fonction de recherche dans l'arbre:
int recherche(t_arbre *arbre, char *chaine)
{
if (arbre == NULL)
return 0;
else if (stricmp(arbre->info, chaine) == 0)
return 1;
else if (stricmp(arbre->info, chaine) < 0)
return recherche(arbre->droite, chaine);
else
return recherche(arbre->gauche, chaine);
}
//Insertion d'un élément de façon ordonné:
void CreerFeuille(char *chaine, t_arbre **arbre)
{
*arbre = (t_arbre*) malloc(1 * sizeof(t_arbre));
//Regarder si strlen + 1 ou seulement strlen, je m'en rappelle jamais
(*arbre)->info = (char*) malloc((strlen(chaine) + 1)*sizeof(char));
strcpy((*arbre)->info, chaine);
(*arbre)->gauche = NULL;
(*arbre)->droite = NULL;
}
void Insertion(t_arbre **arbre, char *chaine)
{
if (*arbre == NULL)
CreerFeuille(chaine, arbre);
else if (stricmp(chaine, (*arbre)->info) >= 0)
(*arbre)->droite = chaine;
else
Insertion(*arbre)->gauche, chaine;
}
//Suppression d'un élément:
void SupprimerNoeud(t_arbre **arbre)
{
t_arbre *p, *q;
p = *arbre;
if ((*arbre)->droite)
{
q = (*arbre)->droite;
while (q->gauche)
q = q->gauche;
q->gauche = p->gauche;
(*arbre) = (*arbre)->gauche;
}
else
(*arbre) = (*arbre)->gauche;
free(p->info);
free(p);
}
void Supprimer(t_arbre **arbre, char *chaine)
{
if (*arbre)
{
if (stricmp((*arbre)->info, chaine) == 0)
SupprimerNoeud(arbre);
else if (stricmp((*arbre)->info, chaine) > 0)
Supprimer(&((*arbre)->gauche), chaine);
else
Supprimer(&((*arbre)->droite), chaine);
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
[/code]