哈夫曼编码-译码器的设计与实现(完整报告及C++源码)

目录

问题描述

系统功能说明

2.1系统功能

2.2 功能详细说明

·初始化(Initialization)

·编码(Encoding)

·译码(Decoding)

·采用凹入表形式打印哈夫曼树(TreePrinting)

数据与结构说明

3.1 数据结构

3.2 模块函数

运行截图

遇到问题及心得体会

5.1 遇到问题

5.2 心得体会

带注释的代码


  • 问题描述

  打开一篇英文文章,统计该文章中每个字符出现的次数,然后以它们作为权值,对每一个字符进行编码,编码完成后再对其编码进行译码。

  利用哈夫曼编码进行信息通信可以大大提高信道利用率,缩短信息传输时间,降低传输成本。但是,这要求在发送端通过一个编码系统对待传数据预先编码,在接收端将传来的数据进行译码(复原)。对于双工信道(即可以双向传输信息的信道),每端都需要一个完整的编/译码系统。试为这样的信息收发站写一个哈夫曼编/译码系统。

  Next morning they met at breakfast. All three were somewhat silent. It was as if the weight of the matter which was that day to be discussed pressed upon their spirits. The smallest of the trio, Septimus Codd by name, who was habitually taciturn, spoke scarcely a word. He was a strange little man, a nineteenth century villain in a sense. He was a rogue and a vagabond, yet his one hobby, apart from his business, was a study of the Past, and many anauthority on Eastern History would have been astonished at the extent of his learning. He was never so happy as when burrowing amongst ancient records, and it was mainly due to his learning in the first place, and to a somewhat singular accident in the second, that the trio were now foregathered in Singapore. His personal appearance was a peculiar one. His height was scarcely more than four feet six inches. His face was round, and at a distance appeared almost boyish. It was only when one came to look into it more closely, that it was seen to be scored by numberless small lines. Moreover it was unadorned by either beard or moustache. His hair was grey, and was worn somewhat longer than is usual. He could speak fluently almost every language of the East, and had been imprisoned by the Russians for sealing in prohibited waters, had been tortured by the Chinese on the Yang-tse, and, to his own unextinguishable disgrace, flogged by the French in Tonquin. Not the least curious trait in his character was the affection he entertained for Kitwater. The pair had been to get her for years, had quarrelled repeatedly, but had never separated. The record of their doings would form an interesting book, but for want of space cannot be more than referred to here. Hayle had been their partner in not a few of their curious undertakings, for his courage and resource made him a valuable ally, though how far they trusted each other it is impossible to say.

  • 系统功能说明
2.1系统功能

功能

实现过程概述

初始化(Initialization)

从文件ToBeTran.txt中读入英文字符集,统计字符出现次数,作为权值建立哈夫曼树,获得哈夫曼编码,并存放于文件hfmCode.txt中。

编码(Encoding)

利用已建好的哈夫曼编码,对文件ToBeTran.txt中的正文进行编码,然后将编码后的结果存入文件CodeFile.txt中。

译码(Decoding)

利用哈夫曼编码将文件CodeFile.txt中的代码进行译码,结果存入文件TextFile.txt中。

打印哈夫曼树(TreePrinting)

将哈夫曼树以凹入表的形式显示在终端上。

2.2 功能详细说明
·初始化Initialization

  1. 打开文件ToBeTran.txt,通过读取文件中的字符来计算英文文章中每个字符的频率(权重),使用noskipws参数保留文件中的空白字符。
  2. 关闭文件。
  3. 按照字符出现的频率(权重)进行排序,组成一个队列queue,出现频率低的在前面,出现频率高的在后面。
  4. 把这些字符作为叶子结点开始构建一棵树。当队列queue中的结点个数大于1时,进行以下操作:
  1. 从队列queue中取出两个频率(权重)最小的结点,并弹出队列queue;
  2. 创建一个新的结点作为这两个结点
  • 21
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

a不是橘子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值