arbre.c 1.61 KB
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>


typedef struct arbre{
    char val;
    struct arbre *suite[26];
    bool finmot; //1 si fin de mot
}Arbre;

typedef struct dico {
    Arbre *alpha[26];
}Dico;





void arbre_vide(struct arbre ** pt_arbre)
{
	*pt_arbre = NULL;
}

bool est_vide(struct arbre *arbre)
{
	return arbre==NULL;
}

bool fin_de_mot(struct arbre *arbre)
{
	return arbre->finmot;
}

void cons_dico(struct dico **pt_dico,char val){
    Dico *mondico=malloc(sizeof(struct dico));
    mondico->alpha[val-97]->val=val; // (ascii)->a = 97
    for(int i=0;i<26;i++){
        mondico->alpha[val-97]->suite[i]=NULL;        
    }
    mondico->alpha[val-97]->finmot=false;
    (*pt_dico)=mondico;
}

void cons_arbre(struct arbre **pt_arbre,char val){
    struct arbre *monarbre=malloc(sizeof(struct arbre));
    monarbre->val=val; // (ascii)->a = 97
    for(int i=0;i<26;i++){
        monarbre->suite[i]=NULL;        
    }
    monarbre->finmot=false;
    (*pt_arbre)=monarbre;
}



void ini_dico(struct dico * pt_dico){
    for(int i=0;i<26;i++){
        cons_dico(&pt_dico,97+i);        
    }
}
  
  
void ajout_mot(struct dico *pt_dico,char mot[]){
    int i=0;
    while(mot[i]!='\0'){
        if (pt_dico->alpha[mot[i]-'a']==NULL){
            cons_arbre(&(pt_dico->alpha[mot[i]-'a']),mot[i]);
            
        }
        i++;
    }
    pt_dico->alpha[mot[i]-'a']->finmot=true;
    
}

void charger_arbre(FILE *fp, struct dico **pt_dico)
{   char mot[20];
    while (fscanf(fp, "%s", mot)!=EOF){
        ajout_mot(*pt_dico,mot);
    }
    return ;
}





int main (){
    
    
    
    
    
    return 0;
}