• [^] # Re: wikipedia ?

    Posté par . En réponse au message [Algorithmie] question sur les arbres binaires. Évalué à 2.

    Je ne cherche pas vraiment à être optimal, plutôt à avoir un truc propre qui marche. Finalement, la fonction que je voulais faire ressemble à ça :
    void index_huffman_tree(unsigned int depth, unsigned int bit, huffman_tree * root, huffman_tree * huffman_index)
    {
     unsigned int char_pos ;
     unsigned int bit_pos ;
     unsigned char bin_mask ;
     unsigned char index ;
     /* modification du noeud de l'arbre */
     root->bit_size = depth ; /* taille du mot en bits */
     char_pos = (depth/CHAR_BIT) ;
     bit_pos = (depth%CHAR_BIT) ;
     if (bit) {
     bin_mask = (unsigned char)(pow(2,bit_pos)) ;
     } else {
     bin_mask = 0 ;
     }
     root->bin_word[char_pos] = (root->bin_word[char_pos] | bin_mask) ;
     /* appel recursif sur les noeuds suivants */
     if( root->left!=NULL && root->right!=NULL )
     {
     index_huffman_tree(depth+1,0,root->left,huffman_index) ;
     index_huffman_tree(depth+1,1,root->right,huffman_index) ;
     }
     else
     {
     i_index = (unsigned char)(root->character) ;
     huffman_index[index] = *root ;
     }
    }