Bonjour, savez vous comment lister les feuilles d'un arbre binaire entier ?
Je cherche une façon de lister les feuilles d'un arbre binaire entier quelconque, et d'y assortir le code binaire correspondant. Merci pour votre aide.
Forum Programmation.autre [Algorithmie] question sur les arbres binaires
5
avr.
2009
# wikipedia ?
Posté par aurel (site web personnel, Mastodon) . Évalué à 2.
[^] # Re: wikipedia ?
Posté par dkremer . Évalué à 1.
unsigned int node_count(huffman_tree * root) { if(root->left!=NULL && root->right!=NULL) { return 1 + node_count(root->left) + node_count(root->right); } else { return 0 ; } } unsigned int depth(huffman_tree * root) { if(root->left!=NULL && root->right!=NULL) { return 1+ ( (depth(root->left) > depth(root->right)) ? depth(root->left) : depth(root->right) ) ; } else { return 0; } }Ce sont des choses qui marchent bien. Je devrai écrire ça de manière récursive, mais je ne vois pas trop comment procéder.[^] # Re: wikipedia ?
Posté par dkremer . Évalué à 1.
[^] # Re: wikipedia ?
Posté par Thibault . Évalué à 2.
[^] # Re: wikipedia ?
Posté par dkremer . Évalué à 2.
[^] # Re: wikipedia ?
Posté par thoasm . Évalué à 2.
[^] # Re: wikipedia ?
Posté par dkremer . Évalué à 2.
[^] # Re: wikipedia ?
Posté par thoasm . Évalué à 2.
[^] # Re: wikipedia ?
Posté par dkremer . Évalué à 2.
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 ; } }[^] # Re: wikipedia ?
Posté par dkremer . Évalué à 2.
http://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_tre(...)
http://fr.wikipedia.org/wiki/Arbre_binaire#Types_d.27arbre_b(...)
[^] # Re: wikipedia ?
Posté par dkremer . Évalué à 2.
# lis ton cours et fait des exos...
Posté par NeoX . Évalué à 4.
Suivre le flux des commentaires
Note : les commentaires appartiennent à celles et ceux qui les ont postés. Nous n’en sommes pas responsables.