西南交通大学_数据结构程序实习作业哈夫曼函数

上传人:zw****58 文档编号:42939624 上传时间:2018-06-04 格式:DOCX 页数:12 大小:18.21KB
返回 下载 相关 举报
西南交通大学_数据结构程序实习作业哈夫曼函数_第1页
第1页 / 共12页
西南交通大学_数据结构程序实习作业哈夫曼函数_第2页
第2页 / 共12页
西南交通大学_数据结构程序实习作业哈夫曼函数_第3页
第3页 / 共12页
西南交通大学_数据结构程序实习作业哈夫曼函数_第4页
第4页 / 共12页
西南交通大学_数据结构程序实习作业哈夫曼函数_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《西南交通大学_数据结构程序实习作业哈夫曼函数》由会员分享,可在线阅读,更多相关《西南交通大学_数据结构程序实习作业哈夫曼函数(12页珍藏版)》请在金锄头文库上搜索。

1、西南交通大西南交通大 学学实验七实验七 哈夫曼函数构造实验哈夫曼函数构造实验 数据结构 A程序实习作业-更新时间 2013/5/26 后有持续更新敬请关注)ECHO DID THIS #include /* for size_t, printf() */ #include /* for getch() */ #include /* for tolower() */ #include /* for malloc(), calloc(), free() */ #include /* for memmove(), strcpy() */*树结构和全局结构指针*/ #define NODENUM 26

2、/*-哈夫曼树结点结构-*/ struct node char ch; int weight; int parent; int lchild,rchild; *ht; /指向哈夫曼树的存储空间的指针变量/*-字符编码结点结构-*/ struct HuffmanCoding char ch; char codingNODENUM; ;/*-哈夫曼树遍历时栈的结点结构-*/ struct stacknode int NodeLevel;int NodeElem; ;/*-常量文件名-*/ const char *TableFileName = “HfmTbl.txt“; /哈夫曼树数据文件 con

3、st char *CodeFileName = “CodeFile.txt“; /字符编码数据文件 const char *SourceFileName = “SrcText.txt“; /需编码的字符串文件 const char *EnCodeFileName = “EnCodeFile.txt“; /编码数据文件 const char *DecodeFileName = “DecodeFile.txt“; /译码字符文件/*/* 释放哈夫曼树数据空间函数 */ /*/ void free_ht() if(ht != NULL) free(ht); ht = NULL; /*/* 从文件读取

4、哈夫曼树数据函数 */ /*/ int ReadFromFile() int i; int m; FILE *fp;if(fp=fopen(TableFileName,“rb“)=NULL) printf(“cannot open %sn“, TableFileName); getch(); return 0; fread( /m 为数据个数 free_ht(); ht=(struct node *)malloc(m*sizeof(struct node); fread(ht,sizeof(struct node),m,fp); fclose(fp); return m; /*/* 吃掉无效的

5、垃圾字符函数函数 */ /* 从键盘读字符数据时使用,避免读到无效字符 */ /*/ void EatCharsUntilNewLine() while(getchar()!=n) continue; /*/* 选择权值最小的两个根结点函数 */ /*/ void Select(struct node ht,int n, int *s1,int *s2) int i,j;/寻找第一个根结点 *s1=0; while (*s17); return(num); void main() while(1) switch(nemu() case 1: Initialization(); break; case 2: Encode(); break; case 3: Decode(); break; case 4:PrintHuffmanTree(); break; case 5:PrintHuffmanTable(); break; case 6:PrintCharCoding(); break; case 7:free_ht(); return;

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

当前位置:首页 > 高等教育 > 其它相关文档

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