Commit 541fd89408058f82f937b30c2ac43e7964c5ba71
1 parent
9cf06b18
on_avance_tree
Showing
3 changed files
with
65 additions
and
29 deletions
Show diff stats
american-english
... | ... | @@ -99152,20 +99152,20 @@ zwieback's |
99152 | 99152 | zygote |
99153 | 99153 | zygote's |
99154 | 99154 | zygotes |
99155 | -Ångström | |
99156 | -éclair | |
99157 | -éclair's | |
99158 | -éclairs | |
99159 | -éclat | |
99160 | -éclat's | |
99161 | -élan | |
99162 | -élan's | |
99163 | -émigré | |
99164 | -émigré's | |
99165 | -émigrés | |
99166 | -épée | |
99167 | -épée's | |
99168 | -épées | |
99169 | -étude | |
99170 | -étude's | |
99171 | -études | |
99155 | +zÅngström | |
99156 | +zéclair | |
99157 | +zéclair's | |
99158 | +zéclairs | |
99159 | +zéclat | |
99160 | +zéclat's | |
99161 | +zélan | |
99162 | +zélan's | |
99163 | +zémigré | |
99164 | +zémigré's | |
99165 | +zémigrés | |
99166 | +zépée | |
99167 | +zépée's | |
99168 | +zépées | |
99169 | +zétude | |
99170 | +zétude's | |
99171 | +zétudes | ... | ... |
... | ... | @@ -43,32 +43,68 @@ int is_leaf(struct node *tree) |
43 | 43 | return tree->fin||tree->fils[0]==NULL; |
44 | 44 | } |
45 | 45 | |
46 | -void add(struct node ***tab_ptr_tree, int val[],int taille, int fl) | |
46 | +void add(struct node ***tab_ptr_tree, char val[],int taille, int fl) | |
47 | 47 | { |
48 | + Node** node = tab_ptr_tree[fl]; | |
48 | 49 | for(int i=0;i<taille;i++) |
49 | 50 | { |
50 | - if(*(tab_ptr_tree[fl])==NULL){cons_tree(tab_ptr_tree[fl],val[i]);continue;} | |
51 | - int trouve = 0; | |
52 | - for(int j=0;j<(*(tab_ptr_tree[fl]))->nbr_fils;j++) | |
51 | + if(node==NULL){ | |
52 | + node = malloc(sizeof(struct node)); | |
53 | + cons_tree(node,val[i]);continue; | |
54 | + printf("%d",(*node)->val); | |
55 | + } | |
56 | + int trouve = -1; | |
57 | + for(int j=0;j<(*node)->nbr_fils;j++) | |
53 | 58 | { |
54 | - if((*(tab_ptr_tree[fl]))->val==val[i]) | |
59 | + if((*node)->fils[j]->val==val[i]) | |
55 | 60 | { |
56 | - trouve=1; | |
61 | + trouve=j; | |
57 | 62 | break; |
58 | 63 | } |
59 | 64 | } |
60 | - if(trouve == 0) | |
61 | - { | |
62 | - //ajouter fils | |
65 | + if(trouve == -1) | |
66 | + {//ajouter fils | |
67 | + (*node)->nbr_fils++; | |
68 | + (*node)->fils = realloc((*node)->fils,((*node)->nbr_fils)*sizeof(struct node*)); | |
69 | + cons_tree(&((*node)->fils[((*node)->nbr_fils)-1]),val[i]); | |
70 | + trouve = 0; | |
63 | 71 | } |
72 | + *node = (*node)->fils[trouve]; | |
73 | + if(i==taille-1) | |
74 | + { | |
75 | + (*node)->fin=1; | |
76 | + } | |
64 | 77 | } |
65 | 78 | //mettre fin à 1 pour le bon |
66 | 79 | //if(i==taille-1)(*(tab_ptr_tree[fl]))->fin=1; // |
67 | 80 | } |
68 | 81 | |
69 | -void load_tree(FILE *fp, struct node **ptr_tree) | |
82 | +int size(char val[]) | |
83 | +{ | |
84 | + int cpt = 0; | |
85 | + while(val[cpt]!='\0') | |
86 | + { | |
87 | + cpt++; | |
88 | + } | |
89 | + return cpt; | |
90 | +} | |
91 | + | |
92 | + | |
93 | +void load_tree(FILE *fp, struct node ***tab_ptr_tree) | |
70 | 94 | { |
71 | 95 | //fl (first letter) |
96 | + char val[50]; | |
97 | + | |
98 | + while(fscanf(fp, "%s",val)==1) | |
99 | + { | |
100 | + if(val[0]<97)val[0]+=32; | |
101 | + val[0]-=97; | |
102 | + add(tab_ptr_tree,val,size(val),(int)val[0]); | |
103 | + } | |
104 | + | |
105 | + //On peut tester la bonne ou mauvaise terminaison de la lecture | |
106 | + if(feof(fp)) printf("Fin normal de lecture\n"); | |
107 | + if(ferror(fp)) printf("ERREUR de lecture\n"); | |
72 | 108 | } |
73 | 109 | |
74 | 110 | void free_tree(struct node **ptr_tree) | ... | ... |
... | ... | @@ -14,8 +14,8 @@ void mk_empty_tree(struct node **); |
14 | 14 | |
15 | 15 | int is_leaf(struct node *); |
16 | 16 | |
17 | -void add(struct node ***, int* ,int ,int); | |
17 | +void add(struct node ***, char* ,int ,int); | |
18 | 18 | |
19 | -void load_tree(FILE *, struct node **); | |
19 | +void load_tree(FILE *, struct node ***); | |
20 | 20 | |
21 | 21 | void free_tree(struct node **); | ... | ... |