![数据结构-课件-ly树代码_第1页](http://file4.renrendoc.com/view/b270f954054bd3ac7e4cf78917c159f6/b270f954054bd3ac7e4cf78917c159f61.gif)
![数据结构-课件-ly树代码_第2页](http://file4.renrendoc.com/view/b270f954054bd3ac7e4cf78917c159f6/b270f954054bd3ac7e4cf78917c159f62.gif)
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
}}#include<iostream>#include<cstdio>#include<cmath>usingnamespacestd;#defineMAX_LEN100voidgotoxy(intx,intCOORDc.X=x-c.Y=y-}typedefstructHuffmanTreeNode{intdata;HuffmanTreeNode*parent,*lChild,*rChild;charcode[MAX_LEN];this->parent=this->lChild=this->rChild=}intgetHeight(HuffmanTreeT){if(T==NULL){returnintlh=getHeight(T->lChild);intrh=getHeight(T->rChild);if(lh>=rh){returnlh+returnrh+}}}voidprint(HuffmanTreeT,intheight,intcurHeight,intleftPos){inty=curHeight;intx=leftPos;if(T!=cout<<T->datainttemp=pow(2,height-curHeight-cout<<}}voidprint(HuffmanTreeT){inth=getHeight(T);intleftPos=pow(2,h-1);}voidGetHuffmanTree(HuffmanTree*HT,int*w,intn){if(n<1)return;intm=2*n-*HT=newHuffmanTreeNode[m+1];HuffmanTreeNode*p=*HT+1;for(inti=1;i<=n;i++){(*p).data=}for(int//在[1~i-1]ints1Pos,s2Pos;intcount=for(intj=1;j<=i-1;j++){if((*HT)[j].parent!=NULL){}if(count==1){s1=&(*HT)[j];s1Pos=j; if(count==2){s2=&(*HT)[j];s2Pos=j;if(s2->data<s1->data){HuffmanTreeNode*temp=s1;s1=s2;s2=temp;intt=s1Pos;s1Pos=s2Pos;s2Pos=t;}intdata=}}if(data<s1->data){s2=s1;s1=s2Pos=s1Pos;s1Pos=j;}elseif(data<s2->data){s2=&(*HT)[j];s2Pos=j;}}}if(s2Pos //intt=s2Pos;s2Pos=s1Pos;s1Pos=t;}s1=&(*HT)[s1Pos];s2=//(*HT)[i].data=s1->data+s2->data;s1->parent=s2->parent=&(*HT)[i];(*HT)[i].lChild=s1;(*HT)[i].rChild=}}voidsetHuffmanCode(HuffmanTreeT,intcurLen){if(T==NULL){}HuffmanTreeNode*p=T->parent;if(p!=NULL){for(int}if(T==p-}//cout<<T->data<<""<<T->code<<}intintn;cin>>n;intfor(inti=0;i<n;i++)cin>>w[
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度厂房装修工程合同管理及咨询服务
- 2025年系列自动遥测气象站项目建议书
- 秋季重点学科教学方案计划
- 秘书职业女性的挑战与机遇计划
- 幼儿表达能力提升计划
- 社区亲和力提升的途径计划
- 资金流动性管理策略计划
- 急诊科应急响应机制强化计划
- 艺术设计行业新年工作策略计划
- 营造积极班级气氛的实践计划
- 苏州地图高清矢量可填充编辑PPT模板(精美)
- 田字格(绿色标准)
- 氧化铝生产工艺教学(拜耳法)PPT课件
- 校本课程——生活中的化学
- 八字调候用神表
- 停车场巡视记录表
- 河道景观设计说明
- 《汽车性能评价与选购》课程设计
- 35kV绝缘导线门型直线杆
- 工程成本分析报告(新)
- 国际学术会议海报模板16-academic conference poster model
评论
0/150
提交评论