Created
August 7, 2022 15:15
-
-
Save LaurentiuGabriel/ef67797a8450f43fbcd1915581846cb7 to your computer and use it in GitHub Desktop.
Tower of Hanoi YouTube Challenge
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 Tower_of_Hanoi { | |
| static void towerOfHanoi(int n, char first_rod, char third_rod, char second_rod){ | |
| if (n == 1) { | |
| System.out.println("Move disk 1 from rod " + first_rod + " to rod " + third_rod); | |
| return; | |
| } | |
| towerOfHanoi(n - 1, first_rod, second_rod, third_rod); | |
| System.out.println("Move disk " + n + " from rod " + first_rod + " to rod " + third_rod); | |
| towerOfHanoi(n - 1, second_rod, third_rod, first_rod); | |
| } | |
| public static void main(String[] args) { | |
| int n = 3; | |
| towerOfHanoi(n, 'A', 'C', 'B'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment