master #2
|
@ -172,6 +172,7 @@ public class BFS<T>
|
|||
private List<int> _closeList = new List<int>();
|
||||
private Queue<int> _openList = new Queue<int>();
|
||||
private Dictionary<Node<T>, Node<T>> _nodeMap = new Dictionary<Node<T>, Node<T>>();
|
||||
private List<int> ids = new List<int>();
|
||||
|
||||
public BFS(Graph<T> graph)
|
||||
{
|
||||
|
@ -186,6 +187,10 @@ public class BFS<T>
|
|||
|
||||
public Path<T> FindPath(Node<T> begin, Node<T> end)
|
||||
{
|
||||
if (begin == null)
|
||||
throw new NullReferenceException("begin");
|
||||
if (end == null)
|
||||
throw new NullReferenceException("end");
|
||||
_openList.Clear();
|
||||
_closeList.Clear();
|
||||
_nodeMap.Clear();
|
||||
|
@ -220,12 +225,6 @@ public class BFS<T>
|
|||
{
|
||||
if (this._nodeMap.TryGetValue(node, out node))
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
Debug.Log($"{node.index} is null");
|
||||
isTrue = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!this.ids.Contains(node.index))
|
||||
{
|
||||
|
@ -234,11 +233,10 @@ public class BFS<T>
|
|||
path.AddNode(new PathNode<T>(node.index, node.data));
|
||||
}
|
||||
}
|
||||
|
||||
if (node == begin)
|
||||
|
||||
if (node==null || node == begin)
|
||||
{
|
||||
Debug.Log("结束了");
|
||||
isTrue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -247,9 +245,6 @@ public class BFS<T>
|
|||
return path;
|
||||
}
|
||||
|
||||
// add
|
||||
private List<int> ids = new List<int>();
|
||||
|
||||
private void Search(Node<T> node)
|
||||
{
|
||||
var readOnlyList = this._graph.GetNeighbours(node);
|
||||
|
|
Loading…
Reference in New Issue