四、综合设计(课程设计)摘要: 在这次课程设计中,所进行的实验是:哈夫曼编码和编译器。对哈夫曼树进行建立,由节点的权值建立最小二叉树,哈夫曼树haftree,并由所建立的哈夫曼树进行编码,求出各个节点的编码。在由所求的哈夫曼树,输入一段二进制电文,能够输出那所建立的哈夫曼树中的节点。建立的haftree用图形化表示出来。在整个代码实现中,窗体的实现,功能的完善,哈夫曼树的建立,哈夫曼树的编码,遇到了许多难题,haftree对象数组的分配空间,节点的属性等都比较困难。在整个过程中,用的是C#语言,包的应用,字符串数组的空间分配,在计算每个字符的权值时,用的是sizeOf()检索整个字符串,计算字符的权值,建立字符出现频度的表格,根据表格中每个字符频度建立起哈夫曼树。从根节点出发检索每个节点的左右孩子,如果是左孩子遍历左边,路径为0,然后左孩子为根节点;如果是右孩子,遍历右孩子,路径为1,然后右孩子为根节点。在重新上述方法,直到所有的节点都遍历完,每个节点的编码就确定后输出来。 在译码过程中,由所输入的二进制电文,根据所建立的哈夫曼树,如果是0走左边,如果是1,走右边,直到节点的左右孩子为空时,输出给节点的信息,在回到根节点重新遍历后面的二进制电文,直到所有电文都遍历完为止,输出所有从电文中译码出来的信息。 关键词:编译器;频度;译码
五、综合设计(课程设计)Abstract:
In this design, the experiment was : Huffman coding and compiler. The Huffman tree to establish, by the node weights to establish a minimum of two fork tree, Huffman tree haftree, and by the Huffman tree coding, and every node coding. By the Huffman tree, enter a binary message, can output the set up by the Huffman tree nodes. Establishment of haftree graphical representation. In the implementation of the code, the realization form, function perfect, Huffman tree is established, Huffman coding tree, encountered a lot of problems, an array of haftree objects allocated space, node attributes are difficult. Throughout the process, using the C# language, the application package, an array of strings in the spatial distribution, calculated for each weight of characters, using sizeOf to retrieve the entire string, calculating the weight of characters, establish character appearance frequency of form, form the basis of each character frequency established Huffman tree. Starting from the root node to retrieve each node around children, if children left traverse left, path 0, then left the child as the root node; if it is right child, traversing the right path for children, 1 children for the root node, then the right. In the new method described above, until all of the node traversal finished, each node is determined after the output coding.
In the decoding process, by the input binary message, according to the established Huffman tree, if it is 0 the left, if it is 1, go right, until the left and right child node is empty, the output to the node information, in the back of the root node to traverse behind a binary message, until all message traversal finished so far, the output from all the message decoding of information.
Keywords: compiler;frequency;decoding
武汉工程大学计算机科学与工程学院 综合设计报告
目 录
摘 要 ................................................................................. 错误!未定义书签。 Abstract................................................................................ 错误!未定义书签。 第一章 设计概述 ............................................................. 错误!未定义书签。 1.1 实验背景 ..................................................................... 错误!未定义书签。 1.2 设计目的 ..................................................................... 错误!未定义书签。 第二章 设计简介及设计方案论述 ................................. 错误!未定义书签。 2.1 方案论述 ..................................................................... 错误!未定义书签。 第三章 详细设计 ............................................................. 错误!未定义书签。 3.1 结构体的定义 ............................................................. 错误!未定义书签。 3.2 主函数定义 ................................................................. 错误!未定义书签。 3.2 副函数定义 ................................................................. 错误!未定义书签。 第四章 设计结果及分析 ................................................. 错误!未定义书签。 4.1 设计结果显示 ............................................................. 错误!未定义书签。 4.2 设计结果分析 ............................................................. 错误!未定义书签。 总 结 ............................................................................... 错误!未定义书签。 致 谢 ............................................................................... 错误!未定义书签。 参考文献 ............................................................................. 错误!未定义书签。 代码附录 ............................................................................. 错误!未定义书签。
- 1 -
武汉工程大学计算机科学与工程学院 综合设计报告
摘 要
在这次课程设计中,所进行的实验是:哈夫曼编码和编译器。对哈夫曼树进行建立,由节点的权值建立最小二叉树,哈夫曼树haftree,并由所建立的哈夫曼树进行编码,求出各个节点的编码。在由所求的哈夫曼树,输入一段二进制电文,能够输出那所建立的哈夫曼树中的节点。建立的haftree用图形化表示出来。在整个代码实现中,窗体的实现,功能的完善,哈夫曼树的建立,哈夫曼树的编码,遇到了许多难题,haftree对象数组的分配空间,节点的属性等都比较困难。在整个过程中,用的是C#语言,包的应用,字符串数组的空间分配,在计算每个字符的权值时,用的是sizeOf()检索整个字符串,计算字符的权值,建立字符出现频度的表格,根据表格中每个字符频度建立起哈夫曼树。从根节点出发检索每个节点的左右孩子,如果是左孩子遍历左边,路径为0,然后左孩子为根节点;如果是右孩子,遍历右孩子,路径为1,然后右孩子为根节点。在重新上述方法,直到所有的节点都遍历完,每个节点的编码就确定后输出来。 在译码过程中,由所输入的二进制电文,根据所建立的哈夫曼树,如果是0走左边,如果是1,走右边,直到节点的左右孩子为空时,输出给节点的信息,在回到根节点重新遍历后面的二进制电文,直到所有电文都遍历完为止,输出所有从电文中译码出来的信息。
关键词:编译器;频度;译码
- - 2
武汉工程大学计算机科学与工程学院 综合设计报告
Abstract
In this design, the experiment was : Huffman coding and compiler. The Huffman tree to establish, by the node weights to establish a minimum of two fork tree, Huffman tree haftree, and by the Huffman tree coding, and every node coding. By the Huffman tree, enter a binary message, can output the set up by the Huffman tree nodes. Establishment of haftree graphical representation. In the implementation of the code, the realization form, function perfect, Huffman tree is established, Huffman coding tree, encountered a lot of problems, an array of haftree objects allocated space, node attributes are difficult. Throughout the process, using the C# language, the application package, an array of strings in the spatial distribution, calculated for each weight of characters, using sizeOf to retrieve the entire string, calculating the weight of characters, establish character appearance frequency of form, form the basis of each character frequency established Huffman tree. Starting from the root node to retrieve each node around children, if children left traverse left, path 0, then left the child as the root node; if it is right child, traversing the right path for children, then the right. In new method described above, until all of the node traversal finished, each node is determined after coding。
In the decoding process, by the input binary message, according to the established Huffman tree, if it is 0 the left, if it is 1, go right, until the left and right child node is empty, the output to the node information, in the back of the root node to traverse behind a binary message, until all message traversal finished so far, the output from all . Keywords: compiler;frequency;decoding
- - 3