1 / 30
文档名称:

数据结构(C语言版)实验报告(哈夫曼树).docx

格式:docx   大小:287KB   页数:30
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

数据结构(C语言版)实验报告(哈夫曼树).docx

上传人:cjl201702 2022/5/15 文件大小:287 KB

下载得到文件列表

数据结构(C语言版)实验报告(哈夫曼树).docx

相关文档

文档介绍

文档介绍:《数据结构与算法》实验报告
需求分析
问题描述:
利用哈夫曼编码进行通信可以大大提高信道利用率,缩短信息传输
时间,降低传输成本。但是,这要求在发送端通过一个编码系统对
待传数据预先编码,在接收端将传来的数据进行译码(复原 ) 。
ofstream outstuf;
typedef struct{
unsigned int weight;
unsigned int parent,lchild,rchild;
} HTNode,*HuffmanTree;
typedef char** HuffmanCode;
HuffmanTree HT=NULL;
int n=0;
HuffmanCode HC=NULL;
char *ch=NULL;
void initHuffmanTree();
int openfileInit();
int inputInit();
int HuffmanCoding(int *w);
void Select(int j,int &s1,int &s2);
void encoding();
void openfileEnco();
void inputEnco();
void decode();
void openfileDeco();
void inputDeco();
void dispHT( HuffmanTree nodeRoot, int level );
void initHuffmanTree(){ // 选择初始化哈夫曼树
int sel=0; for(;;){
cout<<"\t*
********************************************************
"<<endl;
cout<<"\t* "<<" 字符集及权值来源\t\t\t\t\t*"<<endl;
cout<<"\t*\t"<<"1. 进行编码 \t\t\t*"<<endl;
cout<<"\t*\t"<<"2. 自行输入字符集及权值 \t\t\t\t*"<<endl;
cout<<"\t*\t"<<"3. 返回上层 \t\t\t\t\t*"<<endl;
,********************************************************1
cout<〈”请输入您的选择"«endl«" cin»sel;
if(sel==3) break;
switch(sel)
{case 1 :openfilelnit();break;
case 2:inputlnit();break;
default:cout«"对不起,您输入的数据有误!请重新输入。 "<<endl;
)
int openfilelnit(){〃
int *w=(int*)malloc(28*sizeof(int));
ch=(char*)malloc(28*sizeof(char));
n=27;
ifstream infile("",ios::in);
if(!infile){
cerr«"open error!"«endl; exit(1);
cout«"权值文件中的信息(#代表空格)"«endl«endl;
for(int i=1 ;()==0;i++){
infile»ch[i];
infile»w[i]; )
cout«endl;
();
cout«"字符
for(i=1 ;i<10;i++) cout«ch[i]«'\t';
cout«"权值
for(i=1 ;i<10;i++) cout«w[i]«'\t';
cout«"字符
for(i=10;i<19;i++) cout«ch[i]«'\t';
cout«"权值
for(i=10;i<19;i++) cout«w[i]«'\t';
cout«"字符
for(i=19;i<28;i++) cout«ch[i]«'\t';
cout«"权值
for(i=19;i<28;i++) cout«w[i]«'\t';
cout«endl;
n=27;
HuffmanCoding(w);
cout<<" 各字符编码如下: "<<endl;
for(i=1;i<=27;i++) {
cout<<""<<ch[i]<<'\t';
cout<<HC[i]<<endl;
};
("",io