- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
用java实现的经典递归算法(Using java to achieve the classic recursive algorithm)
用java实现的经典递归算法(Using java to achieve the classic recursive algorithm)
First, the reasons for writing this article:
Friends who have studied programming know that the algorithm that calls itself is called a recursive algorithm.
Recursive often brings us is very simple and very intuitive code situation, so that our encoding is greatly simplified, but the recursive thinking is really our conventional thinking is inverse, we are usually thinking from the top down, and the recurrence trend from bottom to top in thinking, because of this, many people have a deep fear for recursion, as I did, now put my experience through several classic examples for beginners and sharing, so this paper, hope for those who need help, if so, it is good...
Two, the basic idea is: recursive algorithm design for a complex problem, the problem is decomposed into several simple sub problems similar to before, to continue until the problem is simple to calculate, which means that the recursive export, so that the problem is a recursive solution.
The key to capture is: (1) recursive exit
(2) push gradually toward the export approach
Three, specific examples
1. Hanoi
This is a recursive example of the super classic, almost every program design book on recursion will be introduced. Specific scenarios will not be repeated. As I mentioned above, (1) the exit of recursion is when the disk number is one
(2) approach the exit: if its not one, its n, then well move the upper n-1 block disk, and when we move up, or when we return recursively, we move the bottom disk..
In this case, a seemingly complex problem is solved, because when the N-1 block disk is moved, it continues to decrease until the number of disk goes up. The Java program code (which has been tested and is running properly) is given below:
Import javax.swing.JOptionPane;
Public, class, Hanoi {
Private, static, final, String, DISK_B = diskB;
Private, static, final, String, DISK_C = diskC;
Private, static, final, String, DISK_A = diskA;
Static
您可能关注的文档
- 怎样制作短剧(How to make short plays).doc
- 心的最里面(全家雾云)(The innermost part of the heart (family, Wu Yun)).doc
- 怎样安排好一天的学习时间、作息时间(How to arrange a day's study time, timetable).doc
- 怎样才能学好c语言(How can I learn C language well).doc
- 怎样让小班新生尽快适应幼儿园的生活(How to make the freshmen adapt to the kindergarten life as soon as possible).doc
- 怎样腌制咸菜更加健康(How salted salted vegetables is healthier).doc
- 怎样调理阳虚体质(How to recuperate Yang deficiency constitution).doc
- 急性荨麻疹勿轻视贪吃海鲜会引发过敏、休克(Acute urticaria does not despise gluttonous seafood can cause allergy, shock).doc
- 怎样选择适合自己个性的职业(How do you choose a career that suits your personality).doc
- 急救知识_警惕夜间降临的急症(First aid _ night emergency alert).doc
- 用制度引导旅游业低碳发展(Guide low carbon development of tourism with system).doc
- 现代复苏时的药物应用(Drug use in modern resuscitation).doc
- 用眼卫生(Eye hygiene).doc
- 用户名大全(Username Daquan).doc
- 用最短的时间了解一个人---fbi阅人术(With the shortest possible time to understand a person ---fbi read human art).doc
- 用短k线寻找股市黑马(In short the stock market dark horse for K).doc
- 用细节提升品牌价值感(Enhance brand value with detail).doc
- 用硫酸亚铁制备氧化铁红介绍(Introduction of ferric oxide red from ferrous sulfate).doc
- 甲磺酸加替沙星葡萄糖注射液(Gatifloxacin Mesylate and Glucose Injection).doc
- 甲状腺突眼(Thyroid ophthalmopathy).doc
最近下载
- 水文分析软件:MIKE 21二次开发_(1).MIKE21概述.docx VIP
- 高中数学人教A版(2019)选择性必修第一册第三章圆锥曲线的方程教学分析和教学建议(课件).pptx
- 清洁生产和清洁生产审核.pptx VIP
- 人教版小学六年级语文上册第五单元测试卷及答案.pdf VIP
- 水族世界行业调研报告解数咨询1016mb.pptx VIP
- 冷库灭火和应急疏散救援预案.docx VIP
- 水文分析软件:MIKE 21二次开发_(10).MIKE21API接口应用.docx VIP
- 供应链风险管理与应急预案.docx VIP
- 酒店前台交接班记录表完整优秀版.docx VIP
- 一种小干扰RNA及其应用专利CN118516357A说明书.pdf
文档评论(0)