gen_code.asv
上传用户:xxhxxny
上传日期:2021-02-19
资源大小:87k
文件大小:1k
- %==============================================
- % 根据Huffman树,生成不同字符的huffman编码,
- % 保存在hufcode中,递归调用
- % 参数:(构建霍夫曼树,根节点,临时霍夫曼编码,临时霍夫曼编码的二进制位数,最终生成的霍夫曼编码)
- %==============================================
- function hufcode = gen_code(huffman_tree,index_tree,tmpcode,tmpbits,hufcode)
- if index_tree <= 256 %递归调用的退出条件
- hufcode.code(index_tree)=tmpcode;
- hufcode.bits(index_tree)=tmpbits;
- return;
- end
- tmpcode=tmpcode*2; %
- tmpbits=tmpbits+1;
- hufcode=gen_code(huffman_tree,huffman_tree.leftchild(index_tree),tmpcode,tmpbits,hufcode);
- hufcode=gen_code(huffman_tree,huffman_tree.rightchild(index_tree),bitor(tmpcode,1),tmpbits,hufcode);