Created
December 7, 2012 01:13
-
-
Save shannah/4229920 to your computer and use it in GitHub Desktop.
Towers of Hanoi changed to use object methods instead of static methods.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.mycompany.myapp; | |
/** | |
* | |
* @author shannah | |
*/ | |
public class TowersOfHanoi { | |
public int counter = 0; | |
public void move(int n, int startPole, int endPole) { | |
if (n == 0) { | |
return; | |
} | |
int intermediatePole = 6 - startPole - endPole; | |
move(n - 1, startPole, intermediatePole); | |
//System.out.println("Move " + n + " from " + startPole + " to " + endPole); | |
move(n - 1, intermediatePole, endPole); | |
counter++; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment