数据结构课程设计哈夫曼编码译码器(23页).doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《数据结构课程设计哈夫曼编码译码器(23页).doc》由会员分享,可在线阅读,更多相关《数据结构课程设计哈夫曼编码译码器(23页).doc(23页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、-题目一:哈夫曼编码与译码一、任务设计一个利用哈夫曼算法的编码和译码系统,重复地显示并处理以下项目,直到选择退出为止。要求:1)将权值数据存放在数据文件(文件名为data.txt,位于执行程序的当前目录中) ;2)初始化:键盘输入字符集统计字符权值、自定义26个字符和26个权值、统计文件中一篇英文文章中26个字母,建立哈夫曼树;3)编码:利用建好的哈夫曼树生成哈夫曼编码;4)输出编码(首先实现屏幕输出,然后实现文件输出);5) 译码(键盘接收编码进行译码、文件读入编码进行译码);6)界面优化设计。二、流程图主菜单1.建立字符权值2.建立并输出哈夫曼树3.建立并查看哈弗曼编码4.编码与译码0.退
2、出系统1.从键盘输入字符集统计权值2.从文件读入字符集统计权值3.自定义字符及权值0.返回上级菜单输出哈夫曼树并保存至文件“哈夫曼树。txt”输出哈夫曼编码并保存至文件“哈夫曼编码。txt1.编码2.译码0.返回上级菜单1.从键盘输入字符集进行编码2.从文件读入字符集进行编码1.从键盘输入编码进行译码2.从文件读入编码进行译码0.返回上级菜单0.返回上级菜单三、代码分解/头文件#include#include#include#include #define N 1000#define M 2*N-1#define MAXcode 6000/函数声明void count(CHar &ch,HTN
3、ode ht);void editHCode(HTNode ht,HCode hcd,CHar &ch,int n,char bianma); /编码函数void printyima(HTNode ht,HCode hcd,int n,char bianma); /译码函数void creatHT(HTNode ht,int n);void CreateHCode (HTNode ht,HCode hcd,int n);void DispHCode(HTNode ht,HCode hcd,int n);void input_key(CHar &ch);void input_file(CHar
4、&ch);void input_cw(HTNode ht);void bianma1(HTNode ht,HCode hcd,CHar &ch,int n,char bianma);void bianma2(HTNode ht,HCode hcd,CHar &ch,int n,char bianma);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 structchar data;int parent;int weight;int lchild;int rchild;HTNode;typedef structchar cdN;int start;HCode;typedef structchar sN;int num;CHar;CHar ch;HTNode htM;HCode hcdN;/主函数int main()int xh;while(1)system(color 1f); /操作菜单背景颜色xh=caidan(); /调用菜单函数 sw
6、itch(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);exit(0);default:system(cls);putchar(a); pr
7、intf(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*= 1.建立字符权值 =*n); printf(tt*= *=*=*=*=*=*=*=*=*
8、=*=*= =*n); 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(tt*= =*n); printf(tt*=*=*=*=*=*=*=*=*=*=*=*=*=
9、*=*=*=*=*=*=*=*=*=*n); printf(ntt请输入序号进行选择:); scanf(%d, &xh); 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*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 2
10、.译码 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 0.返回上级菜单 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(ntt请输入序号进行选择:); scanf(%d,&xh); switch(xh) /switch语句case 1:system(cls);bianmacaidan();break;case 2:system(cls);yimacaidan();break;case 0:system(cls);return;defau
11、lt: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*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 2.文件读入编码进行译码 =*n); pri
12、ntf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 0.返回上级菜单 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(ntt请输入序号进行选择:); scanf(%d,&xh); switch(xh) /switch语句case 1:system(cls);yima1(ht,hcd,n,bianma);break;case 2:system(cls);yima2(ht,hcd,n,bianma);break;case 0:system(cls);return;
13、default:system(cls);putchar(a); printf(ntt输入有误,请重新输入:n);break; void bianmacaidan() 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);
14、 printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 0.返回上级菜单 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(ntt请输入序号进行选择:); scanf(%d,&xh); switch(xh) /switch语句case 1:system(cls);bianma1(ht,hcd,ch,n,bianma);break;case 2:system(cls);bianma2(ht,hcd,ch,n,bianma);break;case 0:syste
15、m(cls);return;default:system(cls);putchar(a); printf(ntt输入有误,请重新输入:n);break; void creat_cw() int xh2; while(1) printf(nnnnn); printf(tt 建立字符权值 n); printf(tt n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 1.从键盘输入字符集进行统计 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*
16、= 2.从文件读入字符集统计 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 3.自定义字符权值 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(tt*= 0.返回上级菜单 =*n); printf(tt*= *=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*n); printf(ntt请输入序号进行选择:); scanf(%d,&xh2); switch(xh2) /switch语句case 1:system(cls);i
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 课程设计 哈夫曼 编码 译码器 23
![提示](https://www.deliwenku.com/images/bang_tan.gif)
限制150内