ImageVerifierCode 换一换
格式:DOCX , 页数:18 ,大小:203.57KB ,
资源ID:20682053      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/20682053.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(0023算法笔记贪心算法哈夫曼编码问题Word文档下载推荐.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

0023算法笔记贪心算法哈夫曼编码问题Word文档下载推荐.docx

1、2. #includestdafx.h3. #includeBinaryTree.h4. #includeMinHeap.h5. #include6. usingnamespacestd;7. 8. constintN=6;9. 10. templateHuffman;11. 12. template13. BinaryTreeHuffmanTree(Typef,intn);14. 15. template16. classHuffman17. 18. friendBinaryTreeHuffmanTree(Type,int);19. public:20. operatorType()cons

2、t21. 22. returnweight;23. 24. /private:25. tree;26. Type27. ;28. 29. intmain()30. 31. charc0,abcdef;32. f0,45,13,12,16,9,5;/下标从1开始33. tHuffmanTree(f,N);34. 35. cout各字符出现的对应频率分别为:endl;36. for(inti=1;i=N;i+)37. 38. ci:fi;39. 40. 41. 42. 生成二叉树的前序遍历结果为:43. t.Pre_Order();44. 45. 46. 生成二叉树的中序遍历结果为:47. t.I

3、n_Order();48. 49. 50. t.DestroyTree();51. 0;52. 53. 54. template55. BinaryTreen)56. 57. /生成单节点树58. Huffman*wnewn+1;59. z,zero;60. 61. =n;62. 63. z.MakeTree(i,zero,zero);64. wi.weightfi;65. wi.treez;66. 67. 68. /建优先队列69. MinHeapQ(n);70. Q.Insert(wi);71. 72. /反复合并最小频率树73. x,y;74. n;75. 76. xQ.RemoveMi

4、n();77. y78. z.MakeTree(0,x.tree,y.tree);79. x.weight+=y.weight;80. x.tree81. Q.Insert(x);82. 83. 84. 85. 86. deletew;87. 88. x.tree;89. (2)BinaryTree.h 二叉树实现1. #include2. using3. 4. template5. structBTNode6. Tdata;8. BTNode*lChild,*rChild;10. BTNode()12. lChild=rChild=NULL;13. 15. BTNode(const&val,

5、BTNode*Childl=NULL,BTNodeCopyTree();30. nr=rChild-nn=new(data,nl,nr);nn;35. ;38. template39. classBinaryTree40. *root;BinaryTree();BinaryTree();voidPre_Order();In_Order();Post_Order();TreeHeight()const;TreeNodeCount()const;52. DestroyTree();54. MakeTree(TpData,BinaryTreeleftTree,BinaryTreerightTree)

6、;55. Change(BTNode*r);56. private:Destroy(BTNode*&r);PreOrder(BTNodeInOrder(BTNodePostOrder(BTNodeHeight(const*r)const;NodeCount(const65. ;67. template68. BinaryTreeBinaryTree()69. root=NULL;71. 73. template74. BinaryTreeBinaryTree()75. 77. 79. template80. voidPre_Order()81. PreOrder(root);83. 85. t

7、emplate86. voidIn_Order()87. InOrder(root);90. 91. template92. voidPost_Order()93. 94. PostOrder(root);95. 96. 97. template98. intTreeHeight()const99. 100. Height(root);101. 102. 103. template104. intTreeNodeCount()const105. 106. NodeCount(root);107. 108. 109. template110. voidDestroyTree()111. 112.

8、 Destroy(root);113. 114. 115. templatedatalChild);122. rChild);123. 124. 125. 126. template132. 133. 134. 135. 136. 137. template143. 144. 145. 146. 147. 148. templatelChild)+NodeCount(r-155. 156. 157. template166. rh=Height(r-167. 1+(lhrh?lh:rh);168. 169. 170. 171. template177. 178. deleter;179. r=

9、NULL;180. 181. 182. 183. templatelChild;189. lChild=r-rChild;190. rChild=p;/左右子女交换191. Change(r-/交换左子树上所有结点的左右子树192. /交换右子树上所有结点的左右子树193. 194. 195. 196. templatedatapData;201. lChildleftTree.root;202. rChildrightTree.root;203. (3)MinHeap.h 最小堆实现1. #include3. template4. classMinHeap5. 6. *heap;/元素数组,

10、0号位置也储存元素CurrentSize;/目前元素个数MaxSize;/可容纳的最多元素个数FilterDown(conststart,constend);/自上往下调整,使关键字小的节点在上FilterUp(intstart);/自下往上调整MinHeap(intn=1000);MinHeap();boolInsert(constx);/插入元素RemoveMin();/删除最小元素GetMin();/取最小元素IsEmpty()const;IsFull()Clear();25. ;27. template28. MinHeap29. MaxSize=n;heap=newTMaxSize;CurrentSize=0;33. 35. template36. MinHeapMinHeap()37. heap;39. 41. template0)if(heapi=temp)break;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1