下载此文档

数据结构哈夫曼编码实现.doc


文档分类:IT计算机 | 页数:约6页 举报非法文档有奖
1/6
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/6 下载此文档
文档列表 文档介绍
#include<>
#include<>
typedef struct haha{
int weight;
int parent,lchild,rchild,flag;
char data;
}haha,*friday;
typedef struct hehe{
char m;
int n;
struct hehe *next;
}hehe,*zhouwu;
typedef char * *gege;
void begin(zhouwu &l)
{
zhouwu p,q,r;
int flag;
l=(zhouwu)malloc(sizeof(hehe));
l->next=NULL;
l->n=0;
r=p=q=l;
printf("请输入要编码的字符串: ");
for(int i=0; ; )
{
p=(zhouwu)malloc(sizeof(hehe));
p->n=0;
p->m=getchar();
if(p->m=='\n')
break;
flag=0;
while(r->next!=NULL)
{
if(r->next->m==p->m)
{
r->next->n++;
flag=1;
free(p);
break;
}
else
r=r->next;
}
if(flag==0)
{
p->next=q->next;
p->n++;
q->next=p;
q=p;
l->n++;
}
r=l;
}
}
void select(friday &ht,int k,int &x,int &y)
{
int first,j[2],m=0,i;
for(int h=1;h<=2;h++)
{
for(first=32767,i=1;i<=k;i++)
{
if(ht[i].flag==0)
{
if(first>ht[i].weight)
{
first=ht[i].weight;
j[m]=i;
}
}
}
x=j[0];
y=j[1];
m++;
ht[x].flag=1;
if(m==2)
ht[y].flag=1;
}
}
void huffmancoding(friday &ht,zhouwu &l)
{
int m;
m=2*l->n-1;
ht=(friday)malloc((m+1)*sizeof(haha));
friday p;
zhouwu q=l;
int i;
for(p=ht+1,i=1;i<=l->n;++i,++p)
{
p->weight=q->next->n;
p->flag=0;
p->parent=0;
p->lchild=0;
p->rchild=0;
p->data=q->next->m;
q=q->next;
}
for( ;i<=m;++i,++p)
{
p->flag=0;
p->weight=0;
p->parent

数据结构哈夫曼编码实现 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数6
  • 收藏数0 收藏
  • 顶次数0
  • 上传人jiaoyuan2014
  • 文件大小50 KB
  • 时间2018-06-01