Skip to content

Commit 65774b4

Browse files
format code
1 parent 4e058de commit 65774b4

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Others/TowerOfHanoi.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
class TowerOfHanoi {
66
public static void shift(int n, String startPole, String intermediatePole, String endPole) {
77
// if n becomes zero the program returns thus ending the loop.
8-
if (n == 0) {
9-
return;
8+
if (n != 0) {
9+
// Shift function is called in recursion for swapping the n-1 disc from the startPole to the intermediatePole
10+
shift(n - 1, startPole, endPole, intermediatePole);
11+
System.out.format("Move %d from %s to %s\n", n, startPole, endPole); // Result Printing
12+
// Shift function is called in recursion for swapping the n-1 disc from the intermediatePole to the endPole
13+
shift(n - 1, intermediatePole, startPole, endPole);
1014
}
11-
12-
13-
// Shift function is called in recursion for swapping the n-1 disc from the startPole to the intermediatePole
14-
shift(n - 1, startPole, endPole, intermediatePole);
15-
System.out.println("%nMove \"" + n + "\" from " + startPole + " --> " + endPole); // Result Printing
16-
// Shift function is called in recursion for swapping the n-1 disc from the intermediatePole to the endPole
17-
shift(n - 1, intermediatePole, startPole, endPole);
1815
}
1916

2017
public static void main(String[] args) {

0 commit comments

Comments
 (0)