Commit 131759eeb563c57f7fdd7938d2f9d229c0ffca1b

Authored by Thorsieger
1 parent 7ab3be6b

fin free arbre

Showing 3 changed files with 17 additions and 9 deletions   Show diff stats
1 a 1 a
  2 +ba
2 aa 3 aa
  4 +ab
3 abc 5 abc
4 -aabc  
5 -aa  
6 -ab  
7 \ No newline at end of file 6 \ No newline at end of file
  7 +c
  8 +d
8 \ No newline at end of file 9 \ No newline at end of file
1 #include "tree.h" 1 #include "tree.h"
  2 +#include "find.h"
2 3
3 int main() 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 if(fp == NULL) return 1 ; //File is not readable 9 if(fp == NULL) return 1 ; //File is not readable
9 10
@@ -19,6 +20,9 @@ int main() @@ -19,6 +20,9 @@ int main()
19 printf("Loading done!\n"); 20 printf("Loading done!\n");
20 21
21 free_dico(tab);//libérer la mémoire 22 free_dico(tab);//libérer la mémoire
22 - 23 + fclose(fp);
  24 +
  25 + printf("Fin du programme\n");
  26 +
23 return 0; 27 return 0;
24 } 28 }
@@ -77,12 +77,14 @@ void load_tree(FILE *fp, struct node **tab_ptr_tree) @@ -77,12 +77,14 @@ void load_tree(FILE *fp, struct node **tab_ptr_tree)
77 77
78 void free_tree(struct node *ptr_tree) 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 free(ptr_tree->fils[i]); 85 free(ptr_tree->fils[i]);
84 } 86 }
85 - //free(ptr_tree); 87 + free(ptr_tree->fils);
86 } 88 }
87 89
88 void free_dico(struct node **tab_ptr_tree) 90 void free_dico(struct node **tab_ptr_tree)
@@ -92,6 +94,7 @@ void free_dico(struct node **tab_ptr_tree) @@ -92,6 +94,7 @@ void free_dico(struct node **tab_ptr_tree)
92 if(tab_ptr_tree[i]!=NULL) 94 if(tab_ptr_tree[i]!=NULL)
93 { 95 {
94 free_tree(tab_ptr_tree[i]); 96 free_tree(tab_ptr_tree[i]);
  97 + free(tab_ptr_tree[i]);
95 } 98 }
96 } 99 }
97 } 100 }