Commit 7a7157b041a96871d216801f6f13ecbfddd8013c
1 parent
41bf8d90
modification creation de arbre
Showing
1 changed file
with
17 additions
and
15 deletions
Show diff stats
arbre.c
... | ... | @@ -32,8 +32,7 @@ bool fin_de_mot(struct arbre *arbre) |
32 | 32 | return arbre->finmot; |
33 | 33 | } |
34 | 34 | |
35 | -void cons_dico(struct dico **pt_dico,char val){ | |
36 | - Dico *mondico=malloc(sizeof(struct dico)); | |
35 | +void cons_dico(struct dico **ppt_dico,char val){ | |
37 | 36 | Arbre *monarbre=malloc(sizeof(struct arbre)); |
38 | 37 | monarbre->val=val; |
39 | 38 | monarbre->finmot=false; |
... | ... | @@ -42,8 +41,7 @@ void cons_dico(struct dico **pt_dico,char val){ |
42 | 41 | monarbre->suite[i]=NULL; |
43 | 42 | } |
44 | 43 | |
45 | - mondico->alpha[val-'a']=monarbre; | |
46 | - (*pt_dico)=mondico; | |
44 | + (*ppt_dico)->alpha[val-'a']=monarbre; | |
47 | 45 | } |
48 | 46 | |
49 | 47 | void ini_dico(struct dico * pt_dico){ |
... | ... | @@ -54,25 +52,27 @@ void ini_dico(struct dico * pt_dico){ |
54 | 52 | } |
55 | 53 | |
56 | 54 | |
57 | -void ajout_mot(struct arbre *pt_arbre,char *mot, int i){ | |
58 | - | |
59 | - while(mot[i]!='\0'){ | |
60 | - | |
61 | - | |
62 | - if (pt_arbre==NULL){ | |
55 | +void ajout_mot(struct arbre **pt_arbre,char *mot, int i){ | |
56 | + printf("%d",i); | |
57 | + printf("%c",mot[i]); | |
58 | + while(mot[i]!='\0'){ | |
59 | + if (*pt_arbre==NULL){ | |
60 | + printf("creation arbre\n"); | |
63 | 61 | Arbre *monarbre=malloc(sizeof(struct arbre)); |
64 | 62 | monarbre->val=mot[i]; |
65 | 63 | monarbre->finmot=false; |
66 | 64 | for(int i=0;i<26;i++){ |
67 | 65 | monarbre->suite[i]=NULL; |
68 | 66 | } |
69 | - pt_arbre=monarbre; | |
67 | + pt_arbre=&monarbre; | |
68 | + printf("%c\n",(*pt_arbre)->val); | |
70 | 69 | |
71 | 70 | } |
72 | 71 | i++; |
73 | 72 | ajout_mot(pt_arbre,mot,i); |
74 | 73 | } |
75 | - | |
74 | +// (*pt_arbre)->finmot=true; | |
75 | +// printf("true\n"); | |
76 | 76 | } |
77 | 77 | |
78 | 78 | void charger_arbre(FILE *fp, struct dico **ppt_dico) |
... | ... | @@ -80,7 +80,8 @@ void charger_arbre(FILE *fp, struct dico **ppt_dico) |
80 | 80 | ini_dico(*ppt_dico); |
81 | 81 | while (fscanf(fp, "%s", mot)!=EOF){ |
82 | 82 | printf("\nmot:%s\n",mot); |
83 | - ajout_mot(((*ppt_dico)->alpha[mot[0]-'a']),mot,0); | |
83 | + printf("%c\n",(*ppt_dico)->alpha[mot[0]-'a']->val); | |
84 | + ajout_mot(&((*ppt_dico)->alpha[mot[0]-'a']),mot,0); | |
84 | 85 | } |
85 | 86 | return ; |
86 | 87 | } |
... | ... | @@ -103,6 +104,7 @@ void free_dico(struct dico *pt_dico){ |
103 | 104 | } |
104 | 105 | for(int i=0;i<26;i++){ |
105 | 106 | free_arbre(pt_dico->alpha[i]); |
107 | + free(pt_dico->alpha[i]); | |
106 | 108 | } |
107 | 109 | free(pt_dico); |
108 | 110 | |
... | ... | @@ -112,7 +114,7 @@ void affiche_arbre(struct arbre *arbre){ |
112 | 114 | if(arbre==NULL){ |
113 | 115 | return ; |
114 | 116 | } |
115 | - printf("%c:xxx\n",arbre->val); | |
117 | + printf("%c\n",arbre->val); | |
116 | 118 | for(int i=0;i<26;i++){ |
117 | 119 | affiche_arbre(arbre->suite[i]); |
118 | 120 | } |
... | ... | @@ -124,7 +126,7 @@ void affiche_dico(struct dico *dico){ |
124 | 126 | } |
125 | 127 | printf("---------------------------------------\n"); |
126 | 128 | for(int i=0;i<26;i++){ |
127 | - printf("%d:zzz",i); | |
129 | + printf("%dmot:",i); | |
128 | 130 | affiche_arbre(dico->alpha[i]); |
129 | 131 | printf("\n"); |
130 | 132 | } | ... | ... |