Bonjour,
le code suivant a pour but de remplacer toutes les occurences d'un mot "mot" par l'arbre "arbremot" qui lui est associé dans l'arbre "arbre".
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 typedef struct noeud { char *mot; struct noeud *gauche; struct noeud *droit; }Noeud,*Arbre;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 void Remplace_aux(Arbre *arbre, char *mot, Arbre arbremot) { if(*arbre != NULL) { if(strcmp((*arbre)->mot,mot) == 0) { (*arbre)->mot = arbremot->mot; (*arbre)->gauche = arbremot->gauche; (*arbre)->droit = arbremot->droit; } else { Remplace_aux(&((*arbre)->gauche),mot,arbremot); Remplace_aux(&((*arbre->droit),mot,arbremot); } } } Arbre Remplace(Arbre *arbre, char *mot, Arbre arbremot) { Arbre tmp; tmp = *arbre; Remplacement_aux(&tmp,mot,arbremot); return tmp; }
Est ce que vous pourriez m'indiquer si le code suivant est correcte et comment je dois m'y prendre pour récupérer l'arbre initial (avant les Remplacement).
Merci d'avance
Partager