数据结构课程设计哈夫曼编码译码器(2020年7月整理).pdf

上传人:摩西的****12 文档编号:141865674 上传时间:2020-08-13 格式:PDF 页数:21 大小:543.95KB
返回 下载 相关 举报
数据结构课程设计哈夫曼编码译码器(2020年7月整理).pdf_第1页
第1页 / 共21页
数据结构课程设计哈夫曼编码译码器(2020年7月整理).pdf_第2页
第2页 / 共21页
数据结构课程设计哈夫曼编码译码器(2020年7月整理).pdf_第3页
第3页 / 共21页
数据结构课程设计哈夫曼编码译码器(2020年7月整理).pdf_第4页
第4页 / 共21页
数据结构课程设计哈夫曼编码译码器(2020年7月整理).pdf_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《数据结构课程设计哈夫曼编码译码器(2020年7月整理).pdf》由会员分享,可在线阅读,更多相关《数据结构课程设计哈夫曼编码译码器(2020年7月整理).pdf(21页珍藏版)》请在金锄头文库上搜索。

1、 1 题目一:哈夫曼编码与译码题目一:哈夫曼编码与译码 一、任务 设计一个利用哈夫曼算法的编码和译码系统,重复地显示并处理以下项目, 直到选择退出为止。 要求: 1) 将权值数据存放在数据文件(文件名为 data.txt,位于执行程序的当前目录 中) ; 2) 初始化:键盘输入字符集统计字符权值、自定义 26 个字符和 26 个权值、统 计文件中一篇英文文章中 26 个字母,建立哈夫曼树; 3) 编码:利用建好的哈夫曼树生成哈夫曼编码; 4) 输出编码(首先实现屏幕输出,然后实现文件输出); 5) 译码(键盘接收编码进行译码、文件读入编码进行译码); 6) 界面优化设计。 二、流程图 三、代码

2、分解 /头文件 #include #include #include #include #define N 1000 #define M 2*N-1 #define MAXcode 6000 /函数声明 void count(CHar void editHCode(HTNode ht,HCode hcd,CHar /编 码函数 void printyima(HTNode ht,HCode hcd,int n,char bianma); /译码函数 void creatHT(HTNode ht,int n); void CreateHCode (HTNode ht,HCode hcd,int n

3、); void DispHCode(HTNode ht,HCode hcd,int n); 主菜单 1.建立字 符权值 2.建立并输出 哈夫曼树 3.建立并查看 哈弗曼编码 4.编码与译码 0.退出系统 1.从键盘输入 字符集统计 2.从文件读入字 符集统计权值 3.自定义字符及 权值 0.返回上级菜单 输出哈夫曼树并保存 至文件“哈夫曼树。 txt” 输出哈夫曼编码并保存至文 件“哈夫曼编码。txt 1.编码 2.译码 0.返回上级 菜单 1.从键盘输入字 符集进行编码 2.从文件读入字 符集进行编码 1.从键盘输入编 码进行译码 2.从文件读入编 码进行译码 0.返回上级菜单 0.返回上级

4、菜单 2 void input_key(CHar void input_file(CHar void input_cw(HTNode ht); void bianma1(HTNode ht,HCode hcd,CHar void bianma2(HTNode ht,HCode hcd,CHar void yima1(HTNode ht,HCode hcd,int n,char bianma); void yima2(HTNode ht,HCode hcd,int n,char bianma); void creat_cw(); void bianmacaidan(); void yimacai

5、dan(); void bianmayima(); int caidan(); /结构体 typedef struct char data; int parent; int weight; int lchild; int rchild; HTNode; typedef struct char cdN; int start; HCode; typedef struct char sN; int num; CHar; CHar ch; HTNode htM; HCode hcdN; 3 /主函数 int main() int xh; while(1) system(color 1f); /操作菜单

6、背景颜色 xh=caidan(); /调用菜单函数 switch(xh) /switch 语句 case 1:system(cls);creat_cw();break; case 2:system(cls);creatHT(ht,n);break; case 3:system(cls);CreateHCode(ht,hcd,n);DispHCode(ht,hcd,n);break; case 4:system(cls);bianmayima();break; case 0:system(cls);printf(nnnnnnnnntttt感 谢 使 用 本 系 统!nnnnnnn ttt);ex

7、it(0); default:system(cls);putchar(a); printf(ntt 输入有误,请重新输入:n);break; return 0; /菜单函数 int caidan() /菜单函数模块/ int xh; printf(nnn); printf(tt 欢迎使用哈夫曼编码译码系统 n); printf(tt n); printf(tt*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*n); printf(tt*= =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*= =*n); printf(tt*=

8、 1.建立字符权值 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*= =*n); 4 printf(tt*= 2.建立并输出哈夫曼树 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*= =*n); printf(tt*= 3.生成并查看哈夫曼编码 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*= =*n); printf(tt*= 4.编码与译码 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*= =*n); printf(tt*= 0.退出系统 =*n); printf

9、(tt*= =*n); printf(tt*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*n); printf(ntt 请输入序号进行选择:); scanf(%d, return xh; /返回从键盘接收的选项 void bianmayima() int xh; while(1) printf(nnnnn); printf(tt 编码与译码 n); printf(tt n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 1.编码 =*n); printf(tt*= *=*=*=

10、*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 2.译码 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 0.返回上级菜单 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(ntt 请输入序号进行选择:); scanf(%d, switch(xh) /switch 语句 case 1:system(cls);bianmacaidan();break; case 2:system(cls);yimacaid

11、an();break; 5 case 0:system(cls);return; default:system(cls);putchar(a); printf(ntt 输入有误,请重新输入:n);break; void yimacaidan() int xh; while(1) printf(nnnnn); printf(tt 译码 n); printf(tt n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 1.键盘输入编码进行译码 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*

12、=*=*=* =*n); printf(tt*= 2.文件读入编码进行译码 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 0.返回上级菜单 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(ntt 请输入序号进行选择:); scanf(%d, switch(xh) /switch 语句 case 1:system(cls);yima1(ht,hcd,n,bianma);break; case 2:system(cls);yima2(ht,

13、hcd,n,bianma);break; case 0:system(cls);return; default:system(cls);putchar(a); printf(ntt 输入有误,请重新输入:n);break; void bianmacaidan() 6 int xh; while(1) printf(nnnnn); printf(tt 编码 n); printf(tt n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 1.键盘输入字符集编码 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 2.文件读入文章编码 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 0.返回上级菜单 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(ntt 请输入序号进行选择:); scanf(%d, switch(xh)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号