| 1 | /*****************************************************************************/ |
| 2 | /* arbre_n_aire.c */ |
| 3 | /* Representation de mots sous forme d'arbre n-aire */ |
| 4 | /*****************************************************************************/ |
| 5 | |
| 6 | #include <stdio.h> |
| 7 | #include <stdlib.h> |
| 8 | #include <string.h> |
| 9 | #include <ctype.h> |
| 10 | |
| 11 | #define N 30 |
| 12 | |
| 13 | |
| 14 | typedef struct noeud { |
| 15 | char lettre; |
| 16 | struct noeud *fils; |
| 17 | struct noeud *frere; |
| 18 | } NOEUD; |
| 19 | |
| 20 | |
| 21 | /* Recherche d'un mot dans l'arbre *****************************************/ |
| 22 | NOEUD *cherche(NOEUD * p, char *mot, int i) |
| 23 | { |
| 24 | if (p == NULL) |
| 25 | return NULL; |
| 26 | if (p->lettre == mot[i]) { |
| 27 | if (mot[i]) |
| 28 | return cherche(p->fils, mot, i + 1); |
| 29 | else |
| 30 | return p; |
| 31 | } else if (p->lettre > mot[i]) |
| 32 | return NULL; |
| 33 | else |
| 34 | return cherche(p->frere, mot, i); |
| 35 | } |
| 36 | |
| 37 | /***************************************************************************/ |
| 38 | NOEUD *recherche(NOEUD * p, char *mot) |
| 39 | { |
| 40 | return cherche(p, mot, 0); |
| 41 | } |
| 42 | |
| 43 | |
| 44 |