From 7d0a632830f52a702d0ad3ffa1f2c20ad721ae48 Mon Sep 17 00:00:00 2001 From: rsimonin Date: Wed, 3 Apr 2019 17:40:32 +0200 Subject: [PATCH] modif creation --- arbre.c | 67 +++++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/arbre.c b/arbre.c index a8e123b..7c34ad7 100644 --- a/arbre.c +++ b/arbre.c @@ -1,6 +1,7 @@ #include #include #include +#include typedef struct arbre{ @@ -15,7 +16,9 @@ typedef struct dico { - +int calculcase(char c){ + return 'c'-'a'; +} void arbre_vide(struct arbre ** pt_arbre) { @@ -32,31 +35,32 @@ bool fin_de_mot(struct arbre *arbre) return arbre->finmot; } -void cons_dico(struct dico **ppt_dico,char val){ - Arbre *monarbre=malloc(sizeof(struct arbre)); - monarbre->val=val; - monarbre->finmot=false; - - for(int i=0;i<26;i++){ - monarbre->suite[i]=NULL; - } - - (*ppt_dico)->alpha[val-'a']=monarbre; -} - void ini_dico(struct dico * pt_dico){ printf("ini_dico\n"); for(int i=0;i<26;i++){ - cons_dico(&pt_dico,'a'+i); + pt_dico->alpha[i]=NULL; } } - - -void ajout_mot(struct arbre **pt_arbre,char *mot, int i){ - printf("%d",i); - printf("%c",mot[i]); - while(mot[i]!='\0'){ - if (*pt_arbre==NULL){ + + +void ajout_mot(struct arbre *arbrecourant,char *mot,int i){ +// Arbre *arbrecourant=malloc(sizeof(struct arbre)); +// if( (*ppt_dico)->alpha[calculcase(mot[0])]==NULL){ +// arbrecourant->val=mot[0]; +// arbrecourant->finmot=false; +// for(int j=0;j<26;j++){ +// arbrecourant->suite[j]=NULL; +// } +// } +// arbrecourant=(*ppt_dico)->alpha[calculcase(mot[0])]; +// +// int i=1; + printf("%s:length:%d\n",mot,strlen(mot)); + + while(mot[i]!='\0'){ + printf("\nlettre:%c; i=%d\n",mot[i],i); + if (arbrecourant->suite[calculcase(mot[i])]==NULL){ + printf("creation arbre\n"); Arbre *monarbre=malloc(sizeof(struct arbre)); monarbre->val=mot[i]; @@ -64,12 +68,13 @@ void ajout_mot(struct arbre **pt_arbre,char *mot, int i){ for(int j=0;j<26;j++){ monarbre->suite[j]=NULL; } - pt_arbre=&monarbre; - printf("%c\n",(*pt_arbre)->val); + arbrecourant=monarbre; +// printf("%c\n",(*pt_arbre)->val); } + arbrecourant=arbrecourant->suite[calculcase(mot[i])]; i++; - ajout_mot(&((*pt_arbre)->suite[mot[i]-'a']),mot,i); + ajout_mot(arbrecourant->suite[calculcase(mot[i])],mot,i); } } @@ -78,9 +83,19 @@ void charger_arbre(FILE *fp, struct dico **ppt_dico) { char mot[20]; ini_dico(*ppt_dico); while (fscanf(fp, "%s", mot)==1){ - int i=0; printf("mot:%s\n",mot); - ajout_mot(&((*ppt_dico)->alpha[mot[0]-'a']),mot,i); + + Arbre *arbrecourant=malloc(sizeof(struct arbre)); + if( (*ppt_dico)->alpha[calculcase(mot[0])]==NULL){ + arbrecourant->val=mot[0]; + arbrecourant->finmot=false; + for(int j=0;j<26;j++){ + arbrecourant->suite[j]=NULL; + } + } + arbrecourant=(*ppt_dico)->alpha[calculcase(mot[0])]; + int i=1; + ajout_mot(&arbrecourant,mot,i); } return ; } -- libgit2 0.21.2