我想使用Stack进行跟踪hanoi堆栈

时间:2017-05-09 15:24:44

标签: java unity3d tracing

我需要使用Stack with Hanoi的游戏塔进行Java跟踪。

注意:我需要4次并显示Stack的角色

这是我在java中的代码:

package towersofhanoi;
import java.util.Scanner;

public class TowersofHanoi {

    public void TOH(int n, String start, String aux, String end) {

           if (n == 1) {
               System.out.println(start + " -> " + end);
           } else {
               TOH(n - 1, start, end, aux);
               System.out.println(start + " -> " + end);
               TOH(n - 1, aux, start, end);
           }
    }

    public static void main(String[] args) {

           TowersofHanoi towersOfHanoi = new TowersofHanoi();

           System.out.print("Enter number of discs: ");
           Scanner scanner = new Scanner(System.in);
           int discs = scanner.nextInt();
           towersOfHanoi.TOH(discs, "A", "B", "C");
    }

}

这是我的Stack(空):

enter image description here

1 个答案:

答案 0 :(得分:0)

在我的国家Ha Noi塔可以解决同样问题:enter image description here

当我编辑你的代码堆栈时不是空的 enter image description here 也许你错过了WrappedComponent