Commit 5a0b8312136f0046a39f44f02fbeab39cfc890cd

Authored by mclaudel
1 parent 7197538b

Algorithme amélioré de manière exceptionnelle le 28/03

Showing 1 changed file with 30 additions and 23 deletions   Show diff stats
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <stdbool.h> 3 #include <stdbool.h>
  4 +#include <string.h>
4 5
5 -#DEFINE MAX_LETTRES 30 6 +#define MAX_LETTRES 30
6 7
7 8
8 typedef struct node { 9 typedef struct node {
  10 + char l;
9 struct node * lettres[27]; 11 struct node * lettres[27];
10 bool fin_de_mot; 12 bool fin_de_mot;
11 int dernier; 13 int dernier;
12 } Node; 14 } Node;
13 15
14 16
15 -void ajout_tete(Node **N, char * mot) 17 +void ajout(Node **N, char mot)
16 { 18 {
17 - Cellule *nouveau = malloc(sizeof(struct node));  
18 - strcpy(nouveau->(*N)->dernier, mot);  
19 - nouveau->suivant = *N; 19 + Node *nouveau = malloc(sizeof(struct node));
  20 + (*nouveau).l=mot;
  21 + for (int i=0; i<27; i++) nouveau->lettres[i]=NULL;
20 *N = nouveau; 22 *N = nouveau;
21 } 23 }
22 24
23 25
24 -void ajout_alphab(Node ** pn, char * mot) 26 +void ajout_alphab(Node ** pn, char * mot,int cpt)
25 { 27 {
26 - if (*pn == NULL)  
27 - {  
28 - ajout_tete(pn,mot);  
29 - }  
30 - else  
31 - {  
32 - if (strcmp(mot, (*pn)->valeur) != 0)  
33 - {  
34 - ajout_alphab(pn[((*pn)->dernier)+1],mot);  
35 - (*pn)->dernier ++;  
36 - } 28 + int i = 0;
  29 + while (mot[cpt] != '\0'){
  30 + while ((*pn)->lettres[i] != NULL){
  31 + if (strcmp(&(*pn)->l,mot) != 0){
  32 + i++;
  33 + }
  34 + *pn=(*pn)->lettres[i];
  35 + return ajout_alphab(pn,mot,cpt++);
37 } 36 }
  37 + ajout(&(*pn)->lettres[i],mot[cpt]);
  38 + *pn=(*pn)->lettres[i];
  39 + cpt++;
  40 + }
38 } 41 }
39 42
40 43
41 -Node * charger_arbre(){  
42 - File * dico; 44 +Node * charger_arbre(Node ** Arbre){
  45 + FILE * dico;
43 char mot[MAX_LETTRES]; 46 char mot[MAX_LETTRES];
44 - *dico = fopen("words.txt",'r'); 47 + dico = fopen("words.txt","r");
45 while (fscanf(dico,"%s",mot) == 1){ 48 while (fscanf(dico,"%s",mot) == 1){
46 - ajout_alphab(Arbre,mot); 49 + ajout_alphab(Arbre,mot,0);
47 } 50 }
48 - fclose();  
49 - return Arbre; 51 + fclose(dico);
  52 + return *Arbre;
50 } 53 }
51 54
  55 +
  56 +int main(){
  57 + return 0;
  58 +}