/递归进行哈夫曼编码*/
void HuffmanCode(HuffmanTree BST,int depth) //depth为目前编码到哈夫曼树的深度(层次)
{
static int code[10]; //编码空间
if( BST ){
if( (BST->Left == NULL) && (BST->Right == NULL)){ //找到了叶结点
printf("字符%c的哈夫曼编码为:",BST->ch);
for(int i=0; i<depth; i++){
printf("%d",code[i]);
}
printf("\n");
}else{
code[depth] = 0; //往左子树方向编码为0
HuffmanCode(BST->Left,depth+1);
code[depth] = 1; //往右子树方向编码为1
HuffmanCode(BST->Right,depth+1);
}
}
}
想问一下这个哈夫曼编码的编码递归有问题嘛