1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include "arbre.h"
void creerArbre(Arbre* a)
{
*a = (Arbre)malloc(sizeof(Noeud));
(*a)->lettre = ' ';
(*a)->fgauche = NULL;
(*a)->fdroit = NULL;
}
void InitArbre(Arbre a, Liste l)
{
int i = 0;
l = l->suiv;
while(l)
{
Arbre b = a;
char* m = l->morse;
for(i = 0; *(m+i) != '\0'; i++)
{
Arbre e;
if (*(m+i)=='.') e = b->fgauche;
else e = b->fdroit;
//Arbre e = (*(m+i) == '.')? b->Gauche: b->Droit;
if(e == NULL)
{
e = (Arbre)malloc(sizeof(Noeud));
e->fgauche = NULL;
e->fdroit = NULL;
if(*(m+i) == '.')
b->fgauche = e;
else
b->fdroit = e;
}
b = e;
}
b->lettre = l->c;
l = l->suiv;
}
}
void Afficher_arbre(Arbre a)
{
if (a!=NULL)
{
Afficher_arbre(a->fdroit);
//Afficher_arbre(a->fgauche);
printf("%c \n",a->lettre);
Afficher_arbre(a->fgauche);
//Afficher_arbre(a->fdroit);
}
}
char ConvertirMorse(char* m, Arbre a)
{
int i = 0;
for (i = 0; *(m+i) != '\0'; i++)
{
if(*(m+i) == '.')
a = a->fgauche;
else
a = a->fdroit;
}
return a->lettre;
} |
Partager