繁体   English   中英

ArrayList中对象的运行方法

[英]Running methods of objects within an ArrayList

我正在创建一个A Star搜索算法来解决8个拼图板,并且我在ArrayList中列出了所有Board对象类。 我的问题是我需要在每个Board对象中运行方法,以使我能够检查它们是否达到了目标,获取Board信息以及与此类似的其他功能。

问题是经过数小时的互联网搜索后,我找不到解决该问题的方法,我尝试使用迭代器来完成似乎正确的方向的工作,但我无法使其正常工作,但是我没有他们没有任何经验。

任何帮助都会有很大帮助。

    public class Solve8Puzzle {
        ArrayList startNode;
        ArrayList nodes;
        public Solve8Puzzle() {
            startNode = new ArrayList();
            nodes = new ArrayList();
        }
        public boolean checkGoalNodes() {
            while( currently selected node has next ) {
                run current node goal check
            }
        }
    }
List<StartNode> startNode = new ArrayList<StartNode>();

.......................


for (StarNode node : starNodes) {
    // do what you want with the node
}

其他可能性

for (Iterator<StarNode> it = starNodes.iterator(); it.hasNext(); ) {
    StarNode node = it.next();
    // do what you want with the node
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM