Commit 5e2228dd419cc1ed45505bf491a4a933b1c1631e
1 parent
d4da0378
projet
Showing
1 changed file
with
100 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,100 @@ | @@ -0,0 +1,100 @@ | ||
1 | +#include <stdlib.h> | ||
2 | +#include <stdio.h> | ||
3 | +#include <string.h> | ||
4 | +#define size 50 | ||
5 | +#define taille 26 | ||
6 | + | ||
7 | +struct Noeud { char valeur;struct liste * fils; char complet;}; | ||
8 | + | ||
9 | +struct liste { struct Noeud * noeud; struct liste * suivant;}; | ||
10 | + | ||
11 | +struct dico {struct Noeud tableau[26];int dernier;}; | ||
12 | + | ||
13 | +typedef struct liste * liste; | ||
14 | + | ||
15 | +typedef struct Noeud Noeud; | ||
16 | + | ||
17 | + | ||
18 | +Noeud cons_noeud (char a) | ||
19 | +{ | ||
20 | + Noeud * N = malloc(sizeof(struct Noeud)); | ||
21 | + N->valeur=a; | ||
22 | + N->fils=NULL; | ||
23 | + N->complet=0; | ||
24 | + return * N; | ||
25 | +} | ||
26 | + | ||
27 | +void ajout_lettre (Noeud * N , char a) | ||
28 | +{ | ||
29 | + if(N==NULL) | ||
30 | + cons_noeud(a); | ||
31 | + else | ||
32 | + { ((N->fils)->noeud)->valeur=a; | ||
33 | + ((N->fils)->noeud)->fils=NULL; | ||
34 | + | ||
35 | + } | ||
36 | +} | ||
37 | + | ||
38 | +//Reprendre cette fonction! | ||
39 | +void ajout_mot (struct dico * D, char mot[size]) | ||
40 | +{ | ||
41 | + Noeud *N; | ||
42 | + for (int j=0;j<D->dernier;j++) | ||
43 | + { if(D->tableau[j].valeur== mot[0]) | ||
44 | + { | ||
45 | + *N=D->tableau[j]; | ||
46 | + } | ||
47 | + else | ||
48 | + { | ||
49 | + *N=cons_noeud(mot[0]); | ||
50 | + } | ||
51 | + | ||
52 | + for (int i=0; i<size; i++) | ||
53 | + | ||
54 | + { | ||
55 | + ajout_lettre (N,mot[i]); | ||
56 | + N=N->fils->noeud; | ||
57 | + } | ||
58 | + N->complet=1; | ||
59 | + } | ||
60 | +} | ||
61 | + | ||
62 | + | ||
63 | +void cons_dico(FILE* fp, struct dico* D) | ||
64 | +{ char a; | ||
65 | + D->dernier=-1; | ||
66 | + if(fp==NULL) | ||
67 | + return; | ||
68 | + while(fscanf(fp,"%s",&a)!=EOF) | ||
69 | + { ajout_mot(D,&a); | ||
70 | + D->dernier++;} | ||
71 | + | ||
72 | +} | ||
73 | + | ||
74 | +int rech_mot(struct dico D,char mot [size]) | ||
75 | +{ | ||
76 | + Noeud N; | ||
77 | + D.dernier=-1; | ||
78 | + for(int i=0;i<D.dernier;i++) | ||
79 | + { | ||
80 | + if(D.tableau[i].valeur==mot[0]) | ||
81 | + { | ||
82 | + N=D.tableau[i]; | ||
83 | + for(int j=0;j<size;j++) | ||
84 | + { | ||
85 | + if(N.valeur==mot[j]) | ||
86 | + *N=N->fils->noeud; | ||
87 | + } | ||
88 | + return 1; | ||
89 | + | ||
90 | + if(N.complet=1) | ||
91 | + return 1; | ||
92 | + } | ||
93 | + else | ||
94 | + return 0; | ||
95 | + } | ||
96 | +} | ||
97 | + | ||
98 | + | ||
99 | + | ||
100 | + |