Huffman

Bonjour,
je cherche le programme de compression de huffman en langage C++, ... j'ai essayé d'écrire mon propre programme mais j'ai pas réussi à mettre les "0" et "1" dans la bonne place et je dois rendre ce programme demain

si c'est possible envoyez moi le code source !!! et j'en serai très reconnaissante

merci d'avance ^^
Configuration: Windows XP
Firefox 3.0.13

4 réponses

  • Votes
  • Date
  • Date décroissante
  1. sa peut d'aider mais c en java pratiquement parail
    bon je l'ai fait y plus d'1 ans donc...

    import java.util.Arrays;
    import javax.swing.JOptionPane;

    public class huffman {

    String Pere;
    char direction;
    char symb;
    int freq;
    String Code;

    public static void main(String[] args) {

    String intro = "";
    intro = intro.toUpperCase();

    while (!(intro=="FIN")){

    intro=JOptionPane.showInputDialog("saisie du texte à encoder");
    int longeur = intro.length();
    huffman tabtri[] = new huffman[longeur];

    System.out.println(intro);

    for (int j = 0; j < tabtri.length; j++) {
    huffman f = new huffman();
    tabtri[j] = f;
    tabtri[j].symb =intro.charAt(j);
    }//end for

    //tri le tableau par ordre de croissant
    char tmp;
    int i;
    for ( i = 0; i < tabtri.length; i++) {
    for (int j = i+1; j < tabtri.length; j++) {
    if (tabtri[i].symb > tabtri[j].symb){
    tmp = tabtri[i].symb;
    tabtri[i].symb= tabtri[j].symb;
    tabtri[j].symb= tmp;
    }//end if
    }//end for
    }//end for

    //indique la fréquence de chaque caractère introduit
    //et les mets dans le tableau.
    int k;
    int cpt = 1;

    for (k = 0; k < tabtri.length-1;k++) {
    if (tabtri[k].symb == tabtri[k+1].symb){
    cpt++;
    tabtri[k].freq = cpt;
    }//end if
    else{ tabtri[k].freq = cpt;
    System.out.println(tabtri[k].symb + " ce caractere a ete introduit "+ cpt + " fois");
    cpt = 1;
    }//end else
    }//end for
    System.out.println(tabtri[k].symb + " ce caractere a ete introduit " + cpt + " fois");
    tabtri[k].freq = cpt;

    }//end While

    }//end main

    }//end class