Yûki - Update Insert and rename rechercher fct
This commit is contained in:
parent
5e43344955
commit
959f1b5938
5 changed files with 58 additions and 38 deletions
|
|
@ -68,7 +68,7 @@ void free_arbre(arbre a)
|
|||
}
|
||||
}
|
||||
|
||||
char *rechercher (arbre a, char c, char*s)
|
||||
char *arbre_rechercher(arbre a, char c, char*s)
|
||||
{
|
||||
if (racine(a)==c)
|
||||
{
|
||||
|
|
@ -76,10 +76,10 @@ char *rechercher (arbre a, char c, char*s)
|
|||
}
|
||||
if (!est_arbre_vide(fils_gauche(a)))
|
||||
{
|
||||
rechercher (fils_gauche(a),c,s+'0') ;
|
||||
arbre_rechercher(fils_gauche(a),c,s+'0') ;
|
||||
}
|
||||
if (!est_arbre_vide(fils_droit(a)))
|
||||
{
|
||||
rechercher (fils_droit(a),c,s+'1') ;
|
||||
arbre_rechercher(fils_droit(a),c,s+'1') ;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,5 +21,5 @@ bool est_arbre_vide(arbre a);
|
|||
|
||||
arbre creer_feuille(Elt e, int p) ;
|
||||
bool est_feuille(arbre a) ;
|
||||
|
||||
char *arbre_rechercher(arbre a, char c, char*s);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -19,32 +19,43 @@ Freq ajouter(int nb, int lettre, Freq l){
|
|||
return tmp;
|
||||
}
|
||||
|
||||
Freq inserer(int nb, int lettre, Freq l){
|
||||
printf("Inserer :\n");
|
||||
Freq inserer(Occ *place, Freq l){
|
||||
printf(" Inserer :\n");
|
||||
if(est_liste_vide(l)){
|
||||
printf("Liste vide :\n");
|
||||
return ajouter(nb,lettre,creer_liste_vide());
|
||||
printf(" Liste vide :\n");
|
||||
return ajouter(place->nb,place->lettre,creer_liste_vide());
|
||||
}
|
||||
else{
|
||||
printf("Liste non vide :\n");
|
||||
printf(" Liste non vide :\n");
|
||||
Occ * tmp;
|
||||
tmp = NULL;
|
||||
Freq new,csl,elem;
|
||||
new = l;
|
||||
elem->nb=nb;
|
||||
elem->lettre=lettre;
|
||||
printf("Boucle : freq : \n",tete_freq(new));
|
||||
while( new && tete_freq(new)<nb){
|
||||
printf("nb: %d / freq : %d \n",nb,tete_freq(new));
|
||||
tmp=new;
|
||||
new = queue(new);
|
||||
tmp = l;
|
||||
if(tmp->suiv == NULL){
|
||||
if(tmp->nb < place->nb){
|
||||
tmp->suiv=place;
|
||||
place->suiv=NULL;
|
||||
}else{
|
||||
place->suiv=tmp;
|
||||
l=place;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
printf("Fin boucle :\n");
|
||||
elem->suiv=csl;
|
||||
tmp->suiv=elem;
|
||||
return tmp;
|
||||
while(tmp->suiv != NULL){
|
||||
if(tmp->suiv->nb >= place->nb){
|
||||
place->suiv=tmp->suiv;
|
||||
tmp->suiv=place;
|
||||
return l;
|
||||
}
|
||||
else{
|
||||
tmp=tmp->suiv;
|
||||
}
|
||||
}
|
||||
// Ajoute à la fin
|
||||
while(l->suiv != NULL){
|
||||
l = l->suiv;
|
||||
}
|
||||
l->suiv=place;
|
||||
return l;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int tete_lettre(Freq l){
|
||||
|
|
@ -76,7 +87,7 @@ Freq liberer_maillon(Freq l){
|
|||
return tmp;
|
||||
}
|
||||
|
||||
int rechercher(int lettre,Freq l){
|
||||
int liste_rechercher(int lettre,Freq l){
|
||||
if(est_liste_vide(l)){
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -84,7 +95,7 @@ int rechercher(int lettre,Freq l){
|
|||
return 1;
|
||||
}
|
||||
else{
|
||||
return rechercher(lettre,queue(l));
|
||||
return liste_rechercher(lettre,queue(l));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,4 +114,13 @@ Freq incrementer(int lettre, Freq l){
|
|||
l->nb++;
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
void afficher(Freq L){
|
||||
printf("Affichage ...\n");
|
||||
while(queue(L) != NULL){
|
||||
printf(" P : %d | Char : %d\n",tete_freq(L),tete_lettre(L));
|
||||
L=queue(L);
|
||||
}
|
||||
printf("Fin Affichage.\n");
|
||||
}
|
||||
|
|
@ -11,13 +11,13 @@ typedef struct zoccurence * Freq;
|
|||
Freq creer_liste_vide();
|
||||
int est_liste_vide(Freq l);
|
||||
Freq ajouter(int nb, int lettre, Freq l);
|
||||
Freq inserer(int nb, int lettre, Freq l);
|
||||
Freq inserer(Occ *place, Freq l);
|
||||
int tete_lettre(Freq l);
|
||||
int tete_freq(Freq l);
|
||||
Freq queue(Freq l);
|
||||
void liberer_liste(Freq l);
|
||||
Freq liberer_maillon(Freq l);
|
||||
int rechercher(int lettre, Freq l);
|
||||
int liste_rechercher(int lettre, Freq l);
|
||||
Freq incrementer(int lettre, Freq l);
|
||||
|
||||
void afficher(Freq L);
|
||||
#endif
|
||||
|
|
@ -49,7 +49,7 @@ Freq freq_apparition(FILE *file){
|
|||
text = creer_liste_vide();
|
||||
int c;
|
||||
while((c=fgetc(file))!=EOF){
|
||||
if(rechercher(c,text)==1){
|
||||
if(liste_rechercher(c,text)==1){
|
||||
text=incrementer(c,text);
|
||||
}
|
||||
else{
|
||||
|
|
@ -73,8 +73,10 @@ arbre huffman(arbre H, Freq L){
|
|||
}
|
||||
int i;
|
||||
i=0;
|
||||
while((L->suiv != NULL)||i<50){
|
||||
while((L->suiv->suiv != NULL)||i<50){
|
||||
printf("Test n°%d \n",i++);
|
||||
l=L;
|
||||
afficher(l);
|
||||
int al,bl,ap,bp;
|
||||
al = tete_lettre(L);
|
||||
ap = tete_freq(L);
|
||||
|
|
@ -87,15 +89,13 @@ arbre huffman(arbre H, Freq L){
|
|||
fd=creer_feuille(bl,bp);
|
||||
H=creer_arbre_huffman(0,ap+bp,fg,fd);
|
||||
printf("Test insérer\n");
|
||||
L=inserer(ap+bp,0,L);
|
||||
printf("Affichage vérification\n");
|
||||
l=L;
|
||||
while(!est_liste_vide(l)){
|
||||
printf("%d (%d)\n",tete_lettre(l),tete_freq(l));
|
||||
l=queue(l);
|
||||
}
|
||||
afficher(l);
|
||||
L=inserer(ajouter(0,ap+bp,creer_liste_vide()),L);
|
||||
l=L;
|
||||
afficher(l);
|
||||
printf("Affichage vérification\n");
|
||||
}
|
||||
|
||||
return H;
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue