设密码电文是由8个字母组成,每个字母在电文中出现的频率分别是7,19,2,6,32,3,21,10写出哈夫曼编码
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/18 16:08:17
![设密码电文是由8个字母组成,每个字母在电文中出现的频率分别是7,19,2,6,32,3,21,10写出哈夫曼编码](/uploads/image/z/8461673-17-3.jpg?t=%E8%AE%BE%E5%AF%86%E7%A0%81%E7%94%B5%E6%96%87%E6%98%AF%E7%94%B18%E4%B8%AA%E5%AD%97%E6%AF%8D%E7%BB%84%E6%88%90%2C%E6%AF%8F%E4%B8%AA%E5%AD%97%E6%AF%8D%E5%9C%A8%E7%94%B5%E6%96%87%E4%B8%AD%E5%87%BA%E7%8E%B0%E7%9A%84%E9%A2%91%E7%8E%87%E5%88%86%E5%88%AB%E6%98%AF7%2C19%2C2%2C6%2C32%2C3%2C21%2C10%E5%86%99%E5%87%BA%E5%93%88%E5%A4%AB%E6%9B%BC%E7%BC%96%E7%A0%81)
设密码电文是由8个字母组成,每个字母在电文中出现的频率分别是7,19,2,6,32,3,21,10写出哈夫曼编码
设密码电文是由8个字母组成,每个字母在电文中出现的频率分别是7,19,2,6,32,3,21,10写出哈夫曼编码
设密码电文是由8个字母组成,每个字母在电文中出现的频率分别是7,19,2,6,32,3,21,10写出哈夫曼编码
O
/ \
/ \
/ \
/ \
(53) (40)
/ \ / \
/ \ / \
(32) (21) (21) (19)
/ \
/ \
(11) (10)
/ \
(6) (5)
/ \
(3) (2)
生成的赫夫曼树,根据左节点为0 右节点为1,从根到叶子的最短路径 如概率32的那个字符可以用00 概率21的那个01 ,概率19的11,概率3 的那个表示成10011.
还有//------------------头文件-------------------------------
#i nclude
#i nclude
#i nclude
#i nclude
#i nclude
#i nclude
#i nclude
typedef int TElemType;
int UINT_MAX=32767;
typedef struct
{
unsigned int weight;
unsigned int parent,lchild,rchild;
}HTNode,* HuffmanTree;
typedef char **HuffmanCode;
//-----------采用全局变量-----------------------
HuffmanTree HT;
HuffmanCode HC;
int *w,i,j,n;
char *z;
int flag=0;
//------------------清空键盘缓冲区---------------
//void Clear_Key_Buffer(void)
//{int offset;
//offset=peek(0x40,0x1a);
//pokeb(0x40,0x1c,offset);
//}
// -----------------求赫夫曼编码-----------------------
int min(HuffmanTree t,int i)
{ // 函数void select()调用
int j,flag;
unsigned int k=UINT_MAX; // 取k为不小于可能的值
for(j=1;j0),构造赫夫曼树HT,并求出n个字符的赫夫曼编码HC
int m,i,s1,s2,start;
unsigned c,f;
HuffmanTree p;
char *cd;
if(n