Yûki - Chain List
This commit is contained in:
parent
a4700a9e3c
commit
04ffeb3403
4 changed files with 82 additions and 25 deletions
|
|
@ -2,8 +2,8 @@
|
|||
#include "arbre_de_codage/arbre_binaire.c"
|
||||
#include "arbre_de_codage/liste.c"
|
||||
|
||||
Freq freq_apparition(FILE *file, int *nb_char);
|
||||
arbre huffman(arbre H, Freq L[]);
|
||||
Freq freq_apparition(FILE *file);
|
||||
arbre huffman(arbre H, Freq L);
|
||||
|
||||
|
||||
// main_compress.c [nom_du_fichier_a_compresser]
|
||||
|
|
@ -13,7 +13,7 @@ int main(int argc, char **argv){
|
|||
const char *mode= "rb";
|
||||
// Vérification de l'existance du second argument (Nom du fichier à compresser)
|
||||
printf("Argc : %d\n",argc);
|
||||
if(argc == 2){
|
||||
if(argc != 2){
|
||||
printf("\nErreur : Veuillez mettre en argument un nom de fichier à compresser (Ex: %s text.txt)\n",argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -22,19 +22,28 @@ int main(int argc, char **argv){
|
|||
printf("\nErreur : Fichier %s inexistant\n",filename);
|
||||
return -2;
|
||||
}
|
||||
printf("test\n");
|
||||
int nb_char;
|
||||
nb_char=0;
|
||||
int *p;
|
||||
p=&nb_char;
|
||||
Freq freq;
|
||||
freq = freq_apparition(file, p);
|
||||
printf("hey");
|
||||
|
||||
// Récupération des fréquences d'apparition des caractères dans le fichier
|
||||
Freq tmp,freq;
|
||||
freq = freq_apparition(file);
|
||||
tmp=freq;
|
||||
// Affichage pour vérification
|
||||
while(!est_liste_vide(tmp)){
|
||||
printf("%d (%d)\n",tete_lettre(tmp),tete_freq(tmp));
|
||||
tmp=queue(tmp);
|
||||
}
|
||||
|
||||
// freq à ordonner dans l'ordre croissant
|
||||
printf("Test Huffman\n");
|
||||
arbre huff;
|
||||
huff = huffman(creer_arbre_vide(),freq);
|
||||
printf("FIN Test Huffman\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Freq freq_apparition(FILE *file, int *nb_char){
|
||||
Freq freq_apparition(FILE *file){
|
||||
Freq text;
|
||||
text = creer_liste_vide();
|
||||
int c;
|
||||
|
|
@ -45,15 +54,44 @@ Freq freq_apparition(FILE *file, int *nb_char){
|
|||
else{
|
||||
text=ajouter(1,c,text);
|
||||
}
|
||||
*nb_char++;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
arbre huffman(arbre H, Freq L[]){
|
||||
arbre huffman(arbre H, Freq L){
|
||||
/*
|
||||
Création de l'arbre de codage de Huffman en considérant une liste avec les fréquences d'apparition des caractères ordonnée croissante
|
||||
*/
|
||||
int i;
|
||||
if(est_liste_vide(L)){
|
||||
printf("Liste vide\n");
|
||||
return H;
|
||||
}
|
||||
else{
|
||||
printf("Liste NON vide\n");
|
||||
// récupérer les deux plus petits poids (cf : deux premieres occurences)
|
||||
arbre A,B,AB;
|
||||
Freq l;
|
||||
l=L;
|
||||
int al,bl,ap,bp;
|
||||
al = tete_lettre(l);
|
||||
ap = tete_freq(l);
|
||||
l = queue(l);
|
||||
bl = tete_lettre(l);
|
||||
bp = tete_freq(l);
|
||||
l = queue(l);
|
||||
|
||||
printf("CREATION ARBRE\n");
|
||||
A = creer_arbre_huffman(al,ap,creer_arbre_vide(),creer_arbre_vide());
|
||||
B = creer_arbre_huffman(bl,bp,creer_arbre_vide(),creer_arbre_vide());
|
||||
AB = creer_arbre_huffman(al*100+bl,ap+bp,A,B);
|
||||
|
||||
l = inserer(ap+bp,al*100+bl,l);
|
||||
printf("test\n");
|
||||
while(!est_liste_vide(l)){
|
||||
printf("%d (%d)\n",tete_lettre(l),tete_freq(l));
|
||||
l=queue(l);
|
||||
}
|
||||
|
||||
}
|
||||
return H;
|
||||
}
|
||||
Reference in a new issue