本文介绍了编写一个程序,使用无信息的搜索技术来解决河内塔楼问题:BFS,DFS和IDS.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编写一个程序以使用不知情的搜索技术(BFS,DFS和IDS)解决河内塔楼问题.
我编写了三个dfs,ids,bfs和Hanoi塔的代码,但我不知道如何将其中一种技术与Hanoi塔问题结合使用.

这是我在这个不错的网站上遇到的第一个问题.
这是我在bfs中的代码:

Write a program to solve the Hanoi towers problem using uninformed search techniques: BFS, DFS and IDS.
I wrote the code of the three dfs, ids,bfs, and Hanoi Towers but I don''t know how to mix one of the techniques with Hanoi towers problem .

This my first question on this nice site.
Here is my code in bfs:

public void bfs()
{
    //BFS uses Queue 
    Queue q=new LinkedList();
    q.add(this.rootNode);
    printNode(this.rootNode);
    rootNode.visited=true;
    while(!q.isEmpty())
    {
        Node n=(Node)q.remove();
        Node child=null;
        while((child=getUnvisitedChildNode(n))!=null)
        {
            child.visited=true;
            printNode(child);
            q.add(child);
        }
    }
    //Clear visited property of nodes
    clearNodes();
}



对于河内来说:



And this for Hanoi:

public class Hanoi {
public static void hanoi(int n, String from, String temp,
String to) {
if (n == 0) return;
hanoi(n-1, from, to, temp);
System.out.println("Move disc " + n +
" from " + from + " to " + to);
hanoi(n-1, temp, from, to);
}
public static void main(String[] args) {
int N = Integer.parseInt(args[0]);
hanoi(N, "A", "B", "C");
}
}



我首先要做的是河内是所有可能解决方案的树
并让bfs跟踪Hanoi节点.

谢谢:)



I will do this first the Hanoi is the tree with all possible solutions
and make the bfs trace the Hanoi nodes.

Thank you :)

推荐答案




这篇关于编写一个程序,使用无信息的搜索技术来解决河内塔楼问题:BFS,DFS和IDS.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 15:43