Yûki - Update Insert (not working)

This commit is contained in:
name 2019-12-12 18:14:33 +01:00
parent 742877f86b
commit 6a10f640c3
No known key found for this signature in database
GPG key ID: 03E8F3CF3183323A
2 changed files with 29 additions and 15 deletions

View file

@ -20,18 +20,31 @@ Freq ajouter(int nb, int lettre, Freq l){
} }
Freq inserer(int nb, int lettre, Freq l){ Freq inserer(int nb, int lettre, Freq l){
Occ *tmp = l; printf("Inserer :\n");
if(est_liste_vide(l)){ if(est_liste_vide(l)){
printf("Liste vide :\n");
return ajouter(nb,lettre,creer_liste_vide()); return ajouter(nb,lettre,creer_liste_vide());
} }
else{ else{
Freq new; printf("Liste non vide :\n");
while(nb>tete_freq(l)){ Occ * tmp;
new=ajouter(nb,lettre,queue(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->suiv=new; printf("Fin boucle :\n");
elem->suiv=csl;
tmp->suiv=elem;
return tmp;
} }
return l;
} }
int tete_lettre(Freq l){ int tete_lettre(Freq l){
@ -83,11 +96,11 @@ Freq incrementer(int lettre, Freq l){
if(est_liste_vide(l)){ if(est_liste_vide(l)){
return l; return l;
} }
else if(lettre == tete_lettre(l)){ else{
while(lettre != tete_lettre(l)){
l=queue(l);
}
l->nb++; l->nb++;
return l; return l;
} }
else{
return incrementer(lettre,queue(l));
}
} }

View file

@ -40,11 +40,10 @@ int main(int argc, char **argv){
arbre huff; arbre huff;
huff = huffman(creer_arbre_vide(),freq); huff = huffman(creer_arbre_vide(),freq);
printf("FIN Test Huffman\n"); printf("FIN Test Huffman\n");
return 0; return 0;
} }
Freq freq_apparition(FILE *file){ Freq freq_apparition(FILE *file){
Freq text; Freq text;
text = creer_liste_vide(); text = creer_liste_vide();
@ -75,7 +74,7 @@ arbre huffman(arbre H, Freq L){
int i; int i;
i=0; i=0;
while((L->suiv != NULL)||i<50){ while((L->suiv != NULL)||i<50){
printf("%d \n",i++); printf("Test n°%d \n",i++);
int al,bl,ap,bp; int al,bl,ap,bp;
al = tete_lettre(L); al = tete_lettre(L);
ap = tete_freq(L); ap = tete_freq(L);
@ -86,8 +85,10 @@ arbre huffman(arbre H, Freq L){
arbre fg,fd; arbre fg,fd;
fg=creer_feuille(al,ap); fg=creer_feuille(al,ap);
fd=creer_feuille(bl,bp); fd=creer_feuille(bl,bp);
H=creer_arbre_huffman(al*100+ap,ap+bp,fg,fd); H=creer_arbre_huffman(0,ap+bp,fg,fd);
L=inserer(ap+bp,al*100+bl,L); printf("Test insérer\n");
L=inserer(ap+bp,0,L);
printf("Affichage vérification\n");
l=L; l=L;
while(!est_liste_vide(l)){ while(!est_liste_vide(l)){
printf("%d (%d)\n",tete_lettre(l),tete_freq(l)); printf("%d (%d)\n",tete_lettre(l),tete_freq(l));