Created
June 14, 2011 12:27
-
-
Save iporsut/1024804 to your computer and use it in GitHub Desktop.
Tower of hanoi in java
This file contains hidden or 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
public class TowerOfHanoi { | |
// move from left to right | |
public static void move(int disk,String srcTower,String tempTower, String dstTower) { | |
if (disk == 1) { | |
System.out.println("Move top disk from " + srcTower + " to " + dstTower); | |
} else { | |
move(disk-1,srcTower,dstTower,tempTower); | |
move(1,srcTower,tempTower,dstTower); | |
move(disk-1,tempTower,srcTower,dstTower); | |
} | |
} | |
public static void main(String []args) { | |
move(3, "left", "center", "right"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment