Commit f00fa1d11401c22e933c51ba5c593d13199bab53
1 parent
7d5276f1
projet0
Showing
2 changed files
with
125 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,65 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | + | |
4 | +#define A 26 | |
5 | + | |
6 | +struct node { | |
7 | + char lettre; | |
8 | + struct cell* listeLettre; | |
9 | +}; | |
10 | + | |
11 | +struct cell { | |
12 | + struct node* arbre; | |
13 | + struct cell* suivant; | |
14 | +}; | |
15 | + | |
16 | +void initialisation_tab_arbre(struct node tab[]) { | |
17 | + for(int i = 0; i < A; i++) { | |
18 | + tab[i].lettre = 97+i; //ajout lettres minuscules | |
19 | + } | |
20 | + /*for(int i = 0; i < 8; i++) { | |
21 | + tab[i+26].lettre = 130+i; //ajout caractères spéciaux | |
22 | + }*/ | |
23 | +} | |
24 | + | |
25 | +void ajout_tete(char elem, struct cell** pL) { | |
26 | + struct cell* p; | |
27 | + p = malloc(sizeof(struct cell)); | |
28 | + p->arbre = malloc(sizeof(struct node)); | |
29 | + p->arbre->lettre = elem; | |
30 | + p->suivant = *pL; | |
31 | + *pL = p; | |
32 | +} | |
33 | + | |
34 | +void insertion(char elem, struct cell** pL) { | |
35 | + if((*pL == NULL)||((*pL)->arbre->lettre > elem)) ajout_tete(elem, pL); | |
36 | + else if((*pL)->arbre->lettre == elem) return; | |
37 | + else insertion(elem, &(*pL)->suivant); | |
38 | +} | |
39 | + | |
40 | +/*void affiche_tab(struct node tab[]) { | |
41 | + for(int i = 0; i < 32; i++) { | |
42 | + printf("%c\n", tab[i].lettre); | |
43 | + } | |
44 | + }*/ | |
45 | + | |
46 | +void lire_fichier(FILE* fd, ) { | |
47 | + | |
48 | +} | |
49 | + | |
50 | +int main(int argc, char* argv[]) { | |
51 | + FILE* fd, | |
52 | + | |
53 | + struct node tab_arbre[A]; | |
54 | + struct node Arbre; | |
55 | + char lettre; | |
56 | + | |
57 | + if(argc>1) fd = fopen(argv[1], "r"); | |
58 | + | |
59 | + Arbre.listeLettre = NULL; | |
60 | + initialisation_tab_arbre(tab_arbre); | |
61 | + scanf("%c", &lettre); | |
62 | + insertion(lettre, &(Arbre.listeLettre)); | |
63 | + //printf("lettre : %c\n", Arbre.listeLettre->arbre->lettre); | |
64 | + return 0; | |
65 | +} | ... | ... |
... | ... | @@ -0,0 +1,60 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | + | |
4 | +#define A 26 | |
5 | + | |
6 | +struct node { | |
7 | + char lettre; | |
8 | + struct cell* listeLettre; | |
9 | +}; | |
10 | + | |
11 | +struct cell { | |
12 | + struct node* arbre; | |
13 | + struct cell* suivant; | |
14 | +}; | |
15 | + | |
16 | +void initialisation_tab_arbre(struct node tab[]) { | |
17 | + for(int i = 0; i < A; i++) { | |
18 | + tab[i].lettre = 97+i; //ajout lettres minuscules | |
19 | + } | |
20 | + /*for(int i = 0; i < 8; i++) { | |
21 | + tab[i+26].lettre = 130+i; //ajout caractères spéciaux | |
22 | + }*/ | |
23 | +} | |
24 | + | |
25 | +void ajout_tete(char elem, struct cell** pL) { | |
26 | + struct cell* p; | |
27 | + p = malloc(sizeof(struct cell)); | |
28 | + p->arbre = malloc(sizeof(struct node)); | |
29 | + p->arbre->lettre = elem; | |
30 | + p->suivant = *pL; | |
31 | + *pL = p; | |
32 | +} | |
33 | + | |
34 | +void insertion(char elem, struct cell** pL) { | |
35 | + if((*pL == NULL)||((*pL)->arbre->lettre > elem)) ajout_tete(elem, pL); | |
36 | + else if((*pL)->arbre->lettre == elem) return; | |
37 | + else insertion(elem, &(*pL)->suivant); | |
38 | +} | |
39 | + | |
40 | +/*void affiche_tab(struct node tab[]) { | |
41 | + for(int i = 0; i < 32; i++) { | |
42 | + printf("%c\n", tab[i].lettre); | |
43 | + } | |
44 | + }*/ | |
45 | + | |
46 | +void lire_fichier() { | |
47 | + | |
48 | +} | |
49 | + | |
50 | +int main() { | |
51 | + struct node tab_arbre[A]; | |
52 | + struct node Arbre; | |
53 | + char lettre; | |
54 | + Arbre.listeLettre = NULL; | |
55 | + initialisation_tab_arbre(tab_arbre); | |
56 | + scanf("%c", &lettre); | |
57 | + insertion(lettre, &(Arbre.listeLettre)); | |
58 | + //printf("lettre : %c\n", Arbre.listeLettre->arbre->lettre); | |
59 | + return 0; | |
60 | +} | ... | ... |