1 /*Hanoi recursion2 * 1.0-n-1 the number of discs, move from tower A to top B3 * 2. Move the 1 discs of number n from a to the top of C4 * 3. Finally, move the N-1 disc above B to the top of C.5 * Note: The plate is numbered from top to bottom 1-n6 * */7 Public classhannotower_recursion {8 9 Public Static voidMain (string[] args) {Ten intNdisk = 3; OneDotowers (Ndisk, ' A ', ' B ', ' C '); A
,char one, char three){if (m==1)Move (One,three);Else{Hanoi (M-1,one,three,two);//The first step is to move a n-1 plate on a C to BMove (One,three);//move a plate to C on the second stepHanoi (M-1,two,one,three);//The third step is to move a n-1 plate on B to C}} Public void Move (char x,char y){System. out. println (x+ "-" +y);}}3 results: Palindrome:1 design ideas:Defines the string, gets the length, and uses the recursive function to determine whe
small plate to the B-pillar temporary storage, the following large plate moved to the C-pillar, and then the B-pillar on the temporary storage of small plates, moved to the C-pillar. * 3 plates: What about more plates? * N Plates * A. Move the top n-1 plate from A, C, to b * B. Move the following plate from a to C * C. Move the n-1 plate from B to the C 2 64-1 times */public class sort02 {static void Hanoi (int n, string src, string mid, S
Li Cuiyun,october 14,2016.Using recursive method to solve the problem of the Han-nuo towerPackage tutorial_3_5;Import java.util.*;public class Hanoitower {public static void Main (string[] args) {TODO auto-generated Method Stub@SuppressWarnings ("resource")Scanner sc=new Scanner (system.in);int n;System.out.println ("Please enter the number of your dished (Hanoi Tower):");N=sc.nextint ();System.out.println
Hanoi Tower problem is: There are ABC three pillars, a pillar from top to bottom stacked a lot of volume in turn, if the disk from a to C pillars, and still keep from top to bottom in order to increment.Class hanio{public void Moveone (int n, string init, String desti) { //The case of only one plate System.out.println ("Move:" +n+ "from" + init+ "to" +desti);} public void Move (int n, string init, String
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.