arbre.c
1.79 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct arbre{
char val;
struct arbre *suite[26];
bool finmot; //1 si fin de mot
}Arbre;
typedef struct dico {
Arbre *alpha[26];
}Dico;
void arbre_vide(struct arbre ** pt_arbre)
{
*pt_arbre = NULL;
}
bool est_vide(struct arbre *arbre)
{
return arbre==NULL;
}
bool fin_de_mot(struct arbre *arbre)
{
return arbre->finmot;
}
void initialise_dico(struct arbre * pt_arbre,char val){
}
void cons_dico(struct dico **pt_dico,char val){
Dico *mondico=malloc(sizeof(struct dico));
mondico->alpha[val-97]->val=val; // (ascii)->a = 97
for(int i=0;i<26;i++){
mondico->alpha[val-97]->suite[i]=NULL;
}
mondico->alpha[val-97]->finmot=false;
(*pt_dico)=mondico;
}
void cons_arbre(struct arbre **pt_arbre,char val){
struct arbre *monarbre=malloc(sizeof(struct arbre));
monarbre->val=val; // (ascii)->a = 97
for(int i=0;i<26;i++){
monarbre->suite[i]=NULL;
}
monarbre->finmot=false;
(*pt_arbre)=monarbre;
}
void ini_dico(struct dico * pt_dico){
for(int i=0;i<26;i++){
cons_dico(&pt_dico,97+i);
}
}
void ajout_mot(struct dico *pt_dico,char mot[]){
int i=0;
while(mot[i]!='\0'){
if (pt_dico->alpha[val[i]-'a']==NULL){
cons_arbre(&(pt_dico->alpha[mot[i]-'a']),mot[i]);
}
i++;
}
pt_dico->alpha[fscval[i]-'a']->finmot=true;
}
void charger_arbre(FILE *fp, struct dico **pt_dico)
{ char mot[20];
while (fscanf(fp, "%s", mot)!=EOF){
ajout_mot(*pt_dico,mot);
// -------------------------------------------------------------
}
return ;
//Tip: use while(fscanf(..) ...)
}
int main (){
return 0;
}