From f5270af0707f4e5f0830191d542a67bd487f152b Mon Sep 17 00:00:00 2001 From: Emilie10 Date: Fri, 3 May 2019 12:40:01 +0200 Subject: [PATCH] projet --- tree.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------- 1 file changed, 87 insertions(+), 39 deletions(-) diff --git a/tree.c b/tree.c index 13ea06e..1cd7faf 100644 --- a/tree.c +++ b/tree.c @@ -1,23 +1,26 @@ #include #include #include -#define size 50 -#define taille 26 +#include +#define size 128 -struct noeud { char valeur; struct noeud * fils[28]; int complet;}; -struct dico {struct noeud* tableau[26];}; +int alphabet[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',39 }; + +struct noeud { char valeur; struct noeud * fils[27]; int complet;}; +struct dico {struct noeud* tableau[26];}; int i; typedef struct noeud* Noeud; -void cons_noeud (Noeud * pN, char a) +Noeud cons_noeud (char a) { - *pN = malloc(sizeof(struct noeud)); - (*pN)->valeur=a; - (*pN)->complet=0; + Noeud pN = malloc(sizeof(struct noeud)); + (*pN).valeur=a; + (*pN).complet=0; for(int i=0; i<28; i++) { - (*pN)->fils[i]=NULL; + (*pN).fils[i]=NULL; } + return pN; } void ajout_noeud_dico(struct dico * D, Noeud N) @@ -28,79 +31,123 @@ void ajout_noeud_dico(struct dico * D, Noeud N) D->tableau[i]=N; } -void ajout_mot(Noeud * pN, char mot[size]) +//tolower --> fonction qui prend une lettre quelconque en argument et renvoie son équivalent en miniscule + +/*void ajout_mot_noeud(Noeud * pN, char mot[size]) { + int j=0; + int n=strlen(mot); if(*pN==NULL) { - cons_noeud(pN,mot[0]); - sup_lettre(mot); + *pN=cons_noeud(tolower(mot[0])); + *pN=(*pN)->fils[j]; } - else - -} + *pN=(*pN)->fils[j]; + printf("%d\n",j); + for(int i=1; ivaleur)!= tolower(mot[i])) + {j++;} + if(j==0) + { + *pN= (*pN)->fils[j+1]; + } + else if (*pN == NULL) + { + *pN =cons_noeud(tolower(mot[i])); + *pN= (*pN)->fils[j]; + } + } + (*pN)->complet=1; +}*/ -char * sup_lettre(char mot[size]) +void ajout_mot_noeud(Noeud * pN, char mot[size]) { - for(int i=1; ivaleur==NULL) + *pN = cons_noeud(tolower(mot[0])); + for(i=1;ialphabet[tolower(mot[i])-'a']; + if(&(*pN)->valeur==NULL) + *pN= cons_noeud(tolower(mot[i])); + } + (*pN)->complet=1; } -//Reprendre cette fonction! +//Reprendre cette fonction! ; + /*void cons_dico_file(FILE* fp, struct dico* D) { char mot[size]; if(fp==NULL) return; - while(fscanf(fp,"%s",a)==1) + while(fscanf(fp,"%s",a)==1)*pN=NULL; { ajout_mot(D,a); - //D->dernier++;} + //D->dernier++;} //int i=O; }*/ + /*int rech_mot(struct dico D,char mot [size]) -{ - Noeud N; +{ char * mot; + mot=sup_lettre("emilie");N)->fils[j]!=NULL || (*pN)->fils[j]->valeur!= mot[i+1]) //int i=O; + {j++;} + printf("%s\n",mot); + Noeud N; //int i=O; int nbre; for(int i=0;inoeud; - else + else //int i=O; nbre=0; } - if(N.complet==1)return newmot - nbre=1; + if(N.complet==1)return newmot //int i=O; + nbre=1;N)->fils[j]!=NULL || (*pN)->fils[j]->valeur!= mot[i+1]) //int i=O; + {j++;} } - else + else char * mot; + mot=sup_lettre("emilie"); //int i=O; + printf("%s\n",mot); nbre= 0; } - return nbre; + return nbre; //int i=O; }*/ /*void correction_texte(char filename[size], struct dico D) { FILE *fp=fopen(filename, "r"); - char mot[size]; - int x; + char mot[size]; //int i=O; + int x; char * mot; +} + mot=sup_lettre("emilie"); + printf("%s\n",mot); if(fp==NULL)return newmot return; - else + else //int i=O; { + for(int i=1; ifils[j]!=NULL || (*pN)->fils[j]->valeur!= mot[i+1]) + {j++;} //int i=O; + mot=sup_lettre("emilie"); + printf("%s\n",mot);eur!\n"); printf("%s",mot); } } @@ -111,9 +158,10 @@ char * sup_lettre(char mot[size]) int main() { - char* newmot; - sup_lettre("emilie"); - + Noeud pN; + pN =cons_noeud('a'); + ajout_mot_noeud(&pN,"arbre"); + printf("%c\n", pN->valeur); return 0; } -- libgit2 0.21.2