Yûki - Add Arbre rechercher (working)
This commit is contained in:
parent
3b30f7714c
commit
b2e8b8f388
3 changed files with 29 additions and 29 deletions
|
|
@ -31,7 +31,7 @@ arbre fils_droit(arbre b)
|
|||
return b->fils_droit;
|
||||
}
|
||||
|
||||
int racine(arbre a)
|
||||
Elt racine(arbre a)
|
||||
{
|
||||
assert(!est_arbre_vide(a));
|
||||
return a->elt;
|
||||
|
|
@ -69,23 +69,19 @@ void free_arbre(arbre a)
|
|||
}
|
||||
}
|
||||
|
||||
char *arbre_rechercher(arbre a, Elt c, char s[])
|
||||
{
|
||||
if(a->elt == c){
|
||||
return s;
|
||||
}
|
||||
if (!est_arbre_vide(fils_gauche(a)))
|
||||
{
|
||||
char c1[]="0";
|
||||
strcat(s,c1);
|
||||
printf("0");
|
||||
arbre_rechercher(fils_gauche(a),c,s);
|
||||
}
|
||||
if (!est_arbre_vide(fils_droit(a)))
|
||||
{
|
||||
char c2[]="1";
|
||||
strcat(s,c2);
|
||||
printf("1");
|
||||
arbre_rechercher(fils_droit(a),c,s);
|
||||
void arbre_rechercher(arbre a, Elt c, char s[], int s_len, int found[]){
|
||||
if(!est_arbre_vide(a)){
|
||||
if(est_feuille(a)&&racine(a)==c){
|
||||
found[0]=1;
|
||||
return ;
|
||||
}
|
||||
if(!est_arbre_vide(fils_gauche(a))&&(found[0]==0)){
|
||||
s[s_len]='0';
|
||||
arbre_rechercher(fils_gauche(a),c,s,s_len+1,found);
|
||||
}
|
||||
if(!est_arbre_vide(fils_droit(a))&&(found[0]==0)){
|
||||
s[s_len]='1';
|
||||
arbre_rechercher(fils_droit(a),c,s,s_len+1,found);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,9 +22,9 @@ arbre creer_arbre_vide(void);
|
|||
arbre creer_arbre_huffman(Elt e, int p, arbre fg, arbre fd);
|
||||
arbre fils_gauche(arbre a);
|
||||
arbre fils_droit(arbre a);
|
||||
int racine(arbre a);
|
||||
Elt racine(arbre a);
|
||||
bool est_arbre_vide(arbre a);
|
||||
arbre creer_feuille(Elt e, int p) ;
|
||||
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
|
||||
|
|
|
|||
|
|
@ -41,13 +41,17 @@ int main(int argc, char **argv){
|
|||
|
||||
// Récupération du code de chaque charactere
|
||||
printf("Code : \n");
|
||||
code C[ASCII_EXT];
|
||||
|
||||
char s[]="";
|
||||
arbre_rechercher(huff,'C',s);
|
||||
printf("\nfin test\n");
|
||||
printf("%s \n",s);
|
||||
printf("FIN\n");
|
||||
char s[8]="2";
|
||||
int f[1]={0};
|
||||
char search=' ';
|
||||
arbre_rechercher(huff,search,s,0,f);
|
||||
if(f[0]==1){
|
||||
printf("\nTrouve : %s\n",s);
|
||||
}
|
||||
else{
|
||||
printf("\nPas Trouve\n");
|
||||
}
|
||||
printf("\nFIN TEST\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +123,7 @@ arbre huffman(arbre T[]){
|
|||
Index=i;
|
||||
while(Index<ASCII_EXT-1){
|
||||
arbre tmp=malloc(sizeof(noeud*));
|
||||
tmp->elt=NULL;
|
||||
tmp->elt=-1;
|
||||
tmp->fils_gauche=T[Index];
|
||||
tmp->fils_droit=T[Index+1];
|
||||
tmp->poids=T[Index]->poids +T[Index+1]->poids;
|
||||
|
|
|
|||
Reference in a new issue