Yûki - Add Arbre rechercher (working)

This commit is contained in:
name 2019-12-15 04:40:57 +01:00
parent 3b30f7714c
commit b2e8b8f388
No known key found for this signature in database
GPG key ID: 03E8F3CF3183323A
3 changed files with 29 additions and 29 deletions

View file

@ -31,7 +31,7 @@ arbre fils_droit(arbre b)
return b->fils_droit; return b->fils_droit;
} }
int racine(arbre a) Elt racine(arbre a)
{ {
assert(!est_arbre_vide(a)); assert(!est_arbre_vide(a));
return a->elt; return a->elt;
@ -69,23 +69,19 @@ void free_arbre(arbre a)
} }
} }
char *arbre_rechercher(arbre a, Elt c, char s[]) void arbre_rechercher(arbre a, Elt c, char s[], int s_len, int found[]){
{ if(!est_arbre_vide(a)){
if(a->elt == c){ if(est_feuille(a)&&racine(a)==c){
return s; found[0]=1;
} return ;
if (!est_arbre_vide(fils_gauche(a))) }
{ if(!est_arbre_vide(fils_gauche(a))&&(found[0]==0)){
char c1[]="0"; s[s_len]='0';
strcat(s,c1); arbre_rechercher(fils_gauche(a),c,s,s_len+1,found);
printf("0"); }
arbre_rechercher(fils_gauche(a),c,s); if(!est_arbre_vide(fils_droit(a))&&(found[0]==0)){
} s[s_len]='1';
if (!est_arbre_vide(fils_droit(a))) arbre_rechercher(fils_droit(a),c,s,s_len+1,found);
{ }
char c2[]="1";
strcat(s,c2);
printf("1");
arbre_rechercher(fils_droit(a),c,s);
} }
} }

View file

@ -22,9 +22,9 @@ arbre creer_arbre_vide(void);
arbre creer_arbre_huffman(Elt e, int p, arbre fg, arbre fd); arbre creer_arbre_huffman(Elt e, int p, arbre fg, arbre fd);
arbre fils_gauche(arbre a); arbre fils_gauche(arbre a);
arbre fils_droit(arbre a); arbre fils_droit(arbre a);
int racine(arbre a); Elt racine(arbre a);
bool est_arbre_vide(arbre a); bool est_arbre_vide(arbre a);
arbre creer_feuille(Elt e, int p) ; arbre creer_feuille(Elt e, int p) ;
bool est_feuille(arbre a) ; bool est_feuille(arbre a) ;
char *arbre_rechercher(arbre a, Elt c, char s[]); void arbre_rechercher(arbre a, Elt c, char s[], int s_len, int found[]);
#endif #endif

View file

@ -41,13 +41,17 @@ int main(int argc, char **argv){
// Récupération du code de chaque charactere // Récupération du code de chaque charactere
printf("Code : \n"); printf("Code : \n");
code C[ASCII_EXT]; char s[8]="2";
int f[1]={0};
char s[]=""; char search=' ';
arbre_rechercher(huff,'C',s); arbre_rechercher(huff,search,s,0,f);
printf("\nfin test\n"); if(f[0]==1){
printf("%s \n",s); printf("\nTrouve : %s\n",s);
printf("FIN\n"); }
else{
printf("\nPas Trouve\n");
}
printf("\nFIN TEST\n");
return 0; return 0;
} }
@ -119,7 +123,7 @@ arbre huffman(arbre T[]){
Index=i; Index=i;
while(Index<ASCII_EXT-1){ while(Index<ASCII_EXT-1){
arbre tmp=malloc(sizeof(noeud*)); arbre tmp=malloc(sizeof(noeud*));
tmp->elt=NULL; tmp->elt=-1;
tmp->fils_gauche=T[Index]; tmp->fils_gauche=T[Index];
tmp->fils_droit=T[Index+1]; tmp->fils_droit=T[Index+1];
tmp->poids=T[Index]->poids +T[Index+1]->poids; tmp->poids=T[Index]->poids +T[Index+1]->poids;