Commit 131759eeb563c57f7fdd7938d2f9d229c0ffca1b
1 parent
7ab3be6b
fin free arbre
Showing
3 changed files
with
17 additions
and
9 deletions
Show diff stats
dico_test
1 | 1 | #include "tree.h" |
2 | +#include "find.h" | |
2 | 3 | |
3 | 4 | int main() |
4 | 5 | { |
5 | - FILE* fp = fopen("american-english","r"); | |
6 | - //FILE* fp = fopen("dico_test","r"); | |
6 | + //FILE* fp = fopen("american-english","r"); | |
7 | + FILE* fp = fopen("dico_test","r"); | |
7 | 8 | |
8 | 9 | if(fp == NULL) return 1 ; //File is not readable |
9 | 10 | |
... | ... | @@ -19,6 +20,9 @@ int main() |
19 | 20 | printf("Loading done!\n"); |
20 | 21 | |
21 | 22 | free_dico(tab);//libérer la mémoire |
22 | - | |
23 | + fclose(fp); | |
24 | + | |
25 | + printf("Fin du programme\n"); | |
26 | + | |
23 | 27 | return 0; |
24 | 28 | } | ... | ... |
... | ... | @@ -77,12 +77,14 @@ void load_tree(FILE *fp, struct node **tab_ptr_tree) |
77 | 77 | |
78 | 78 | void free_tree(struct node *ptr_tree) |
79 | 79 | { |
80 | - for(int i=0;i<ptr_tree->nbr_fils;i++) | |
80 | + if(ptr_tree==NULL)return; | |
81 | + if(ptr_tree->nbr_fils==0){free(ptr_tree->fils);return;} | |
82 | + for(int i=(ptr_tree->nbr_fils)-1;i>=0;i--) | |
81 | 83 | { |
82 | - if(ptr_tree->fils[i]->nbr_fils!=0)free_tree(ptr_tree->fils[i]); | |
84 | + free_tree(ptr_tree->fils[i]); | |
83 | 85 | free(ptr_tree->fils[i]); |
84 | 86 | } |
85 | - //free(ptr_tree); | |
87 | + free(ptr_tree->fils); | |
86 | 88 | } |
87 | 89 | |
88 | 90 | void free_dico(struct node **tab_ptr_tree) |
... | ... | @@ -92,6 +94,7 @@ void free_dico(struct node **tab_ptr_tree) |
92 | 94 | if(tab_ptr_tree[i]!=NULL) |
93 | 95 | { |
94 | 96 | free_tree(tab_ptr_tree[i]); |
97 | + free(tab_ptr_tree[i]); | |
95 | 98 | } |
96 | 99 | } |
97 | 100 | } | ... | ... |