tree.c
3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define size 128
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;
Noeud cons_noeud (char a)
{
Noeud pN = malloc(sizeof(struct noeud));
(*pN).valeur=a;
(*pN).complet=0;
for(int i=0; i<28; i++)
{
(*pN).fils[i]=NULL;
}
return pN;
}
void ajout_noeud_dico(struct dico * D, Noeud N)
{
int i=0;
while(D->tableau[i]!=NULL)
{i++;}
D->tableau[i]=N;
}
//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)
{
*pN=cons_noeud(tolower(mot[0]));
*pN=(*pN)->fils[j];
}
*pN=(*pN)->fils[j];
printf("%d\n",j);
for(int i=1; i<n; i++)
{
while((*pN)!=NULL && tolower((*pN)->valeur)!= 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;
}*/
void ajout_mot_noeud(Noeud * pN, char mot[size])
{
int i,n=strlen(mot);
if(& (*pN)->valeur==NULL)
*pN = cons_noeud(tolower(mot[0]));
for(i=1;i<n;i++)
{
pN=&(*pN)->alphabet[tolower(mot[i])-'a'];
if(&(*pN)->valeur==NULL)
*pN= cons_noeud(tolower(mot[i]));
}
(*pN)->complet=1;
}
//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)*pN=NULL;
{ ajout_mot(D,a);
//D->dernier++;} //int i=O;
}*/
/*int rech_mot(struct dico D,char mot [size])
{ 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;i<D.dernier;i++)
{
if(D.tableau[i].valeur==mot[0])
{ char * mot; //int i=O;
mot=sup_lettre("emilie");
printf("%s\n",mot);
N=D.tableau[i];
for(int j=0;j<size;j++)
{ //int i=O;
if(N.valeur==mot[j])
N=*(N.fils)->noeud;
else //int i=O;
nbre=0;
}
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 char * mot;
mot=sup_lettre("emilie"); //int i=O;
printf("%s\n",mot);
nbre= 0;
}
return nbre; //int i=O;
}*/
/*void correction_texte(char filename[size], struct dico D)
{
FILE *fp=fopen(filename, "r");
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 //int i=O;
{
for(int i=1; i<size; i++)
{
mot[i]= newmot[i-1];
} //int i=O;
while(fscanf(fp,"%s",mot)==1)
{
x=rech_mot(D,mot);
if(x==0)
{
printf("il y a une err char * mot;N)->fils[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);
}
}
}
}*/
int main()
{
Noeud pN;
pN =cons_noeud('a');
ajout_mot_noeud(&pN,"arbre");
printf("%c\n", pN->valeur);
return 0;
}