资源简介
实现了Huffman编码算法:
1、使用链表结构。
2、使用《数据结构》(严蔚敏,C语言版)中给出的算法;
3、增加预先排序的功能的算法

代码片段和文件信息
#include
#include
#include
#include
#include
#define NULL 0
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define MAX_NUM 10000
#define MAX 60
typedef int Status;
typedef char **HuffmanCode;
typedef struct{
unsigned int weight;
unsigned int parentlchildrchild;
}HTNode*HuffmanTree;
typedef struct{
HuffmanTree HT;
char *c;
int longth;
HuffmanCode HC;
}Huffman;
void Select(HuffmanTree HTint endint *s1int *s2)
{
int i;
int min1=MAX_NUM;
int min2;
for (i=1;i<=end;i++)
{
if (HT[i].parent==0 && HT[i].weight {
*s1=i;
min1=HT[i].weight;
}
}
min2=MAX_NUM;
for(i=1;i<=end;i++)
{
if(HT[i].parent==0&&(*s1!=i)&&min2>HT[i].weight)
{
*s2=i;
min2=HT[i].weight;
}
}
}
Huffman HuffmanCoding(Huffman Hfm)
{
/*---------------------------------*/
int inms1s2start;
int cf;
char *cd;
n=Hfm.longth;
if(n<=1) return Hfm;
m=2*n-1;
for(i=n+1;i<=m;++i)
{
Select(Hfm.HTi-1&s1&s2);
Hfm.HT[s1].parent=i;
Hfm.HT[s2].parent=i;
Hfm.HT[i].lchild=s1;
Hfm.HT[i].rchild=s2;
Hfm.HT[i].weight=Hfm.HT[s1].weight+Hfm.HT[s2].weight;
}
/*------------------------------------------*/
Hfm.HC=(HuffmanCode)malloc((n+1)*sizeof(char *));
cd=(char *)malloc(n*sizeof(char));
cd[n-1]=‘\0‘;
for(i=1;i<=n;++i)
{
start=n-1;
for(c=if=Hfm.HT[i].parent;f!=0;c=ff=Hfm.HT[f].parent)
{
if(c==Hfm.HT[f].lchild) cd[--start]=‘0‘;
else cd[--start]=‘1‘;
}
Hfm.HC[i]=(char *)malloc((n-start)*sizeof(char));
strcpy(Hfm.HC[i]&cd[start]);
}
free(cd);
return Hfm;
}
Huffman InputHuffman(Huffman Hfm)
{
int in;
system(“cls“);
printf(“\n\n\t\t********************Initial*********************\n“);
printf(“\tThe chars and weights will be saved in the file \“hfmTree\“\n“);
printf(“Please input the number of the chars: “);
scanf(“%d“&n);
Hfm.HT=(HuffmanTree)malloc((2*n)*sizeof(HTNode));
Hfm.c=(char *)malloc((n+1)*sizeof(char));
for(i=1;i<=n;i++)
{
printf(“Please input the char: “);
scanf(“%s“&Hfm.c[i]);
printf(“Please input the weight of the char: “);
scanf(“%d“&Hfm.HT[i].weight);
Hfm.HT[i].parent=0;
Hfm.HT[i].lchild=0;
Hfm.HT[i].rchild=0;
}
for(;i<=2*n-1;++i)
{
Hfm.HT[i].weight=0;
Hfm.HT[i].parent=0;
Hfm.HT[i].lchild=0;
Hfm.HT[i].rchild=0;
}
Hfm.longth=n;
return Hfm;
}
Huffman InitHuffman(Huffman Hfm)
{
int ni;
FILE *fp;
fp=fopen(“hf
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 7699 2010-04-24 21:53 hefuman\11.cpp
文件 3353 2010-04-25 16:31 hefuman\11.dsp
文件 512 2010-04-25 18:34 hefuman\11.dsw
文件 41984 2010-04-25 18:34 hefuman\11.ncb
文件 48640 2010-04-25 18:34 hefuman\11.opt
文件 736 2010-04-25 16:32 hefuman\11.plg
文件 0 2010-04-25 16:35 hefuman\CodeFile
文件 4291 2010-04-20 22:08 hefuman\hefuman.dsp
文件 522 2010-04-20 21:50 hefuman\hefuman.dsw
文件 33792 2010-04-20 22:08 hefuman\hefuman.ncb
文件 48640 2010-04-20 22:08 hefuman\hefuman.opt
文件 692 2010-04-20 21:56 hefuman\hefuman.plg
文件 0 2010-04-25 18:30 hefuman\hfmTree
文件 53 2010-04-25 16:36 hefuman\TextFile
文件 213041 2010-04-25 16:32 hefuman\Debug\11.exe
文件 239692 2010-04-25 16:32 hefuman\Debug\11.ilk
文件 21491 2010-04-25 16:31 hefuman\Debug\11.obj
文件 230516 2010-04-24 13:16 hefuman\Debug\11.pch
文件 1188864 2010-04-24 21:53 hefuman\Debug\11.pdb
文件 0 2010-04-29 17:49 hefuman\Debug\CodeFile
文件 213046 2010-04-20 21:50 hefuman\Debug\hefuman.exe
文件 235516 2010-04-20 21:50 hefuman\Debug\hefuman.ilk
文件 230516 2010-04-20 21:50 hefuman\Debug\hefuman.pch
文件 459776 2010-04-20 21:50 hefuman\Debug\hefuman.pdb
文件 18 2010-04-29 17:14 hefuman\Debug\hfmTree
文件 74752 2010-04-25 18:30 hefuman\Debug\vc60.idb
文件 110592 2010-04-24 21:53 hefuman\Debug\vc60.pdb
目录 0 2010-04-30 21:20 hefuman\Debug
目录 0 2010-04-30 21:20 hefuman
----------- --------- ---------- ----- ----
............此处省略2个文件信息
- 上一篇:OSPF基于C语言的算法实现
- 下一篇:ymodem发送代码(c语言)
相关资源
- 百度C++编码规范
- GBT 28169-2011 嵌入式软件 C语言编码规范
- 缩短循环码(2616)编译码程序-C语言
- pcm语音编码
- UNIX/LINUX下C语言中文短信UCS2编码和解
- 信息论课程设计——LZW编码
- c语言实现bch编码
- 个人总结的一些C/C++编码规范
- 谷歌C++编码规范 Google C++ 风格指南
- C语言实现LZW编码
- C++实现的改进遗传算法
- c++ 数据结构 哈夫曼压缩&解压软件 控
- C++文本文件无失真压缩 Huffman
- MFC莫尔斯电码的编码发声
- Google-C++编码规范中文版最新整理PDF版
- spiht算法小波图像编码算法
- GBT28169-2011嵌入式软件C语言编码规范
- 嵌入式软件C语言编码规范(高安全性
- 密码编码学:加密方法的C与C++实现
- MMX-密码编码学:加密方法的C与C++实现
- MFC 一维码生成+打印 支持多种编码1
- Huffman和算术编码的C++实现
- 基于JPEG2000的图像编码与解码c++版
- 简单实现的自适应算术编码
- 谷歌C++编码规范-中文 2018-03-30 最新版
- jbig二值图像压缩算法编码实现
- VC++串口通信编码
- 哈夫曼编码译码器数据结构
- 编码:隐匿在计算机软硬件背后的语
- vc++ 图像编码 视频编码
评论
共有 条评论