2

I am working on a project that i must traverse a maze using the left-hand rule and based upon the intersections the program comes upon i need to create a node to connect to a graph that I will then determine the shortest path. The goal is for the program to run through the maze then close out the program and read from a file that contains the graph and determines the shortest path to the finish. what i have done is i can traverse the maze using the left-hand rule. what im thinking to do is create a node when i find the intersection and there after every time the program moves i increase the cost of that path by one. on a side note do you need to have an adjacency matrix when use dijkstra's algorithm?

4

1 回答 1

2

尝试这样的事情,它应该工作:

0 - 创建一个空的“解决方案路径”堆栈位置对象。

1 - 如果当前位置是迷宫出口,则返回“解决方案路径”堆栈。

2 - 前面的墙?左转并重复 2,否则继续 3。

3 - 如果当前位置位于“解决方案路径”堆栈的顶部,
       将其从堆栈中弹出
       否则将其压入堆栈

4 - 前进。

当您检查堆栈顶部的当前位置时,您可能需要检查最后一个元素之前的元素,因为最后一个元素将是您刚刚离开的位置。

于 2010-07-27T04:16:23.230 回答