Hanio (for my memory of Grade One)
2011-08-27 09:54
381 查看
突然想起大一学递归的时候,c++那本教材上的汉诺塔例子,当时不是很理解,今天翻出来看,有一番新感觉,有了新的体会,果然人真的是会成长的。当时觉得有点难的东西现在不会那么困惑了,所以说熟能生巧,时间也是能改变许多东西的。
/* 2011-8-27 author:BearFly1990 */ package temp; import java.util.Scanner; public class Hanio { public static void main(String[] args) { Scanner console = new Scanner(System.in); while(true){ int m = console.nextInt(); hanio(m,'a','b','c'); } } public static void hanio(int m, char one, char two, char three){ if( m == 1){ move(one , three); }else{ hanio(m-1,one,three,two); move(one,three); hanio(m-1,two,one,three); } } public static void move(char x, char y){ System.out.println(x+"--->"+y); } }
相关文章推荐
- How to discover memory usage of my application in Android
- New Technique: Tachyon (used memory instead of disk for HDFS)
- C#Memory Management for Unity Developers(Part 1 of 3)
- wrote a single layer of deep html document procedures for my dear
- How to discover memory usage of my application in Android
- the diary for one command application of pipe in Linux
- New Technique: Tachyon (used memory instead of disk for HDFS)
- Android studio遇到 java.lang.OutOfMemoryError: GC app:transformClassesWithDexForDebug解决方法 以及gradle优化
- Astronomy poj 3101 数论 分数的最小公倍数 Cherish the memory of my broken heart
- Out of memory. Type HELP MEMORY for your options (
- Server(Admin) start is failing in WLST as outofmemory error permgen space for weblogic 12c
- New Technique: Tachyon (used memory instead of disk for HDFS)
- C#Memory Management for Unity Developers (part 2 of 3)
- 93.You are using flat files as the data source for one of your data warehousing applications. To opt
- SurfaceFlinger/gralloc Out of Memory error when allocating buffer memory for use with virtual frame
- Some of my experiences for cocos2d-x+lua
- At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs d
- C# Memory Management for Unity Developers (part 3 of 3)
- Image.FromFile gives "Out of Memory" Exception for icon
- some kind of explanation for my splendid life