欢迎来到天天文库
浏览记录
ID:48870625
大小:275.00 KB
页数:11页
时间:2020-02-03
《大数据结构实验三哈夫曼树实验报告材料.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、实用文档题目:哈夫曼编/译码器一、题目要求:写一个哈夫曼码的编/译码系统,要求能对要传输的报文进行编码和解码。构造哈夫曼树时,权值小的放左子树,权值大的放右子树,编码时右子树编码为1,左子树编码为0.二、概要设计:数据结构:typedefstruct{intbit[MAXBIT];intstart;}HCodeType;/*编码结构体*/typedefstruct{intweight;intparent;intlchild;intrchild;charvalue;}HNode;/*结点结构体*/
2、函数:voidDEMONHuffmanTree(HNodeHuffNode[MAXNODE],intn)作用:构造一个哈夫曼树,并循环构建intmain()作用:运用已经构建好的哈弗曼树,进行节点的处理,达到成功解码编译三、详细设计:哈夫曼树的建立:voidDEMONHuffmanTree(HNodeHuffNode[MAXNODE],intn){inti=0,j,m1,m2,x1,x2;charx;/*初始化存放哈夫曼树数组HuffNode[]中的结点*/while(i3、[i].weight=0;//权值实用文档HuffNode[i].parent=-1;HuffNode[i].lchild=-1;HuffNode[i].rchild=-1;scanf("%c",&x);scanf("%c",&HuffNode[i].value);//实际值,可根据情况替换为字母i++;}/*输入n个叶子结点的权值*/scanf("%c",&x);for(i=0;i4、i++){HuffNode[i].weight=0;//权值HuffNode[i].parent=-1;HuffNode[i].lchild=-1;HuffNode[i].rchild=-1;HuffNode[i].value=i;}/*循环构造Huffman树*/for(i=0;i5、+){if(HuffNode[j].weight6、fNode[x2].parent=n+i;HuffNode[n+i].weight=HuffNode[x1].weight+HuffNode[x2].weight;HuffNode[n+i].lchild=x1;HuffNode[n+i].rchild=x2;}}叶子节点的哈夫曼编码的保存:for(j=cd.start+1;j7、ffNode[MAXNODE];HCodeTypeHuffCode[MAXLEAF],cd;inti,j,c,p,n,k=0;charwen[100];charz;scanf("%d",&n);HuffmanTree(HuffNode,n);for(i=0;i8、it[cd.start]=1;cd.start--;/*求编码的低一位*/c=p;p=HuffNode[c].parent;/*设置下一循环条件*/}/*endwhile*/实用文档for(j=cd.start+1;j
3、[i].weight=0;//权值实用文档HuffNode[i].parent=-1;HuffNode[i].lchild=-1;HuffNode[i].rchild=-1;scanf("%c",&x);scanf("%c",&HuffNode[i].value);//实际值,可根据情况替换为字母i++;}/*输入n个叶子结点的权值*/scanf("%c",&x);for(i=0;i4、i++){HuffNode[i].weight=0;//权值HuffNode[i].parent=-1;HuffNode[i].lchild=-1;HuffNode[i].rchild=-1;HuffNode[i].value=i;}/*循环构造Huffman树*/for(i=0;i5、+){if(HuffNode[j].weight6、fNode[x2].parent=n+i;HuffNode[n+i].weight=HuffNode[x1].weight+HuffNode[x2].weight;HuffNode[n+i].lchild=x1;HuffNode[n+i].rchild=x2;}}叶子节点的哈夫曼编码的保存:for(j=cd.start+1;j7、ffNode[MAXNODE];HCodeTypeHuffCode[MAXLEAF],cd;inti,j,c,p,n,k=0;charwen[100];charz;scanf("%d",&n);HuffmanTree(HuffNode,n);for(i=0;i8、it[cd.start]=1;cd.start--;/*求编码的低一位*/c=p;p=HuffNode[c].parent;/*设置下一循环条件*/}/*endwhile*/实用文档for(j=cd.start+1;j
4、i++){HuffNode[i].weight=0;//权值HuffNode[i].parent=-1;HuffNode[i].lchild=-1;HuffNode[i].rchild=-1;HuffNode[i].value=i;}/*循环构造Huffman树*/for(i=0;i5、+){if(HuffNode[j].weight6、fNode[x2].parent=n+i;HuffNode[n+i].weight=HuffNode[x1].weight+HuffNode[x2].weight;HuffNode[n+i].lchild=x1;HuffNode[n+i].rchild=x2;}}叶子节点的哈夫曼编码的保存:for(j=cd.start+1;j7、ffNode[MAXNODE];HCodeTypeHuffCode[MAXLEAF],cd;inti,j,c,p,n,k=0;charwen[100];charz;scanf("%d",&n);HuffmanTree(HuffNode,n);for(i=0;i8、it[cd.start]=1;cd.start--;/*求编码的低一位*/c=p;p=HuffNode[c].parent;/*设置下一循环条件*/}/*endwhile*/实用文档for(j=cd.start+1;j
5、+){if(HuffNode[j].weight6、fNode[x2].parent=n+i;HuffNode[n+i].weight=HuffNode[x1].weight+HuffNode[x2].weight;HuffNode[n+i].lchild=x1;HuffNode[n+i].rchild=x2;}}叶子节点的哈夫曼编码的保存:for(j=cd.start+1;j7、ffNode[MAXNODE];HCodeTypeHuffCode[MAXLEAF],cd;inti,j,c,p,n,k=0;charwen[100];charz;scanf("%d",&n);HuffmanTree(HuffNode,n);for(i=0;i8、it[cd.start]=1;cd.start--;/*求编码的低一位*/c=p;p=HuffNode[c].parent;/*设置下一循环条件*/}/*endwhile*/实用文档for(j=cd.start+1;j
6、fNode[x2].parent=n+i;HuffNode[n+i].weight=HuffNode[x1].weight+HuffNode[x2].weight;HuffNode[n+i].lchild=x1;HuffNode[n+i].rchild=x2;}}叶子节点的哈夫曼编码的保存:for(j=cd.start+1;j7、ffNode[MAXNODE];HCodeTypeHuffCode[MAXLEAF],cd;inti,j,c,p,n,k=0;charwen[100];charz;scanf("%d",&n);HuffmanTree(HuffNode,n);for(i=0;i8、it[cd.start]=1;cd.start--;/*求编码的低一位*/c=p;p=HuffNode[c].parent;/*设置下一循环条件*/}/*endwhile*/实用文档for(j=cd.start+1;j
7、ffNode[MAXNODE];HCodeTypeHuffCode[MAXLEAF],cd;inti,j,c,p,n,k=0;charwen[100];charz;scanf("%d",&n);HuffmanTree(HuffNode,n);for(i=0;i8、it[cd.start]=1;cd.start--;/*求编码的低一位*/c=p;p=HuffNode[c].parent;/*设置下一循环条件*/}/*endwhile*/实用文档for(j=cd.start+1;j
8、it[cd.start]=1;cd.start--;/*求编码的低一位*/c=p;p=HuffNode[c].parent;/*设置下一循环条件*/}/*endwhile*/实用文档for(j=cd.start+1;j
此文档下载收益归作者所有