课程设计首页 课程设计首页 数据结构课程设计 数据结构课程设计 C语言课程设计 C语言课程设计 电子课程设计 电子课程设计 微机原理课程设计 微机原理课程设计 机械设计课程设计 机械设计课程设计 软件工程课程设计 软计工程课程设计 平面设计课程设计 平面设计课程设计 单片机课程设计 单片机课程设计  课程设计报告 课程设计报告 课程设计心得体会 课程设计心得体会
           
课程设计栏目热门文章
·学生成绩管理系统(c语言)
·图邻接矩阵 邻接表的建立c
·图书管理系统c++版_数据结
·通讯录(c++)_数据结构课
·稀疏矩阵运算器数_据结构
·停车场管理器_数据结构课
·航班_数据结构课程设计 我
·数据结构的课程设计总结
·成绩管理系统c语言版
·数据结构课程设计_赫夫曼
·数据结构课程设计_校园导
·数据结构课程设计_迷宫问
·数据结构课程设计_算术表
·数据结构课程数据_飞机订
·数据结构课程设计_单链表
·数据结构课程设计_图的遍
·数据结构课程设计_Huffman
·数据结构课程设计_用静态
·数据结构课程设计_成绩管
·数据结构课程设计_joseph
·数据结构课程设计_文本编
·数据结构课程设计_迷宫问
·数据结构课程设计_拓扑排
·数据结构课程设计_几种常
当前位置:首页>数据结构课程设计> 正文
数据结构课程设计_哈夫曼编\译码器代码
文章发布:课程设计网 发布时间:2006-12-01
# define max 50 
struct a 

int weight; 
int parent,lchild,rchild; 
}; 
struct b 

char cd[max]; 
int start; 
}; 
main() 

struct a ht[2*max]; 
struct b hcd[max],d; 
int i,j,k,n,c,s1,s2,m1,m2,f; 
printf("shu ru n:
"); 
scanf("%d",&n); 
for(i=1;i<=n;i++) 

printf("shu ru quan zhi :"); 
scanf("%d",&ht[i].weight); 
ht[i].parent=0; 

for(;i<=2*n-1;i++) 
ht[i].parent=ht[i].lchild=ht[i].rchild=0; 
for(i=n+1;i<=2*n-1;i++) 

m1=m2=30000; 
s1=s2=0; 
for(k=1;k<=i-1;k++) 

if(ht[k].parent==0 && ht[k].weight<m1) 

m2=m1; 
s2=s1; 
m1=ht[k].weight; 
s1=k; 

else if(ht[k].parent==0 && ht[k].weight<m2) 

m2=ht[k].weight; 
s2=k; 


ht[s1].parent=ht[s2].parent=i; 
ht[i].lchild=s1; 
ht[i].rchild=s2; 
ht[i].weight=ht[s1].weight+ht[s2].weight; 

for(i=1;i<=n;i++) 

d.start=n-1; 
c=i; 
f=ht[i].parent; 
while(f) 

if(ht[f].lchild==c)d.cd[--d.start]='0'; 
else d.cd[--d.start]='1'; 
c=f; 
f=ht[f].parent; 

hcd[i]=d; 

printf("shu chu ha fu bian ma "); 
for(i=1;i<=n;i++) 

printf("%d ",ht[i].weight); 
for(k=hcd[i].start;k<n-1;k++) 
printf("%c",hcd[i].cd[k]); 
printf(" "); 

}


上一篇:平面设计课程设计_台湾平面经典设计作品   下一篇:操作系统课程设计_先进先出页面置换算法
COPYRIGHT© 2006-2008 WWW.UT365.COM ONLINE SERVICES. ALL RIGHTS RESERVED. 鲁ICP备05047946号