C# Graph Traversal

后端 未结 4 1128
刺人心
刺人心 2021-02-02 00:45

This algorithm does a great job of traversing the nodes in a graph.

Dictionary visited = new Dictionary();

Queue         


        
4条回答
  •  醉梦人生
    2021-02-02 01:21

    Peter is almost correct. I don't think you can store a link to the parent vertex in the node class, because it changes depending on the vertex at which you start your breadth first search. You need to create a Parent Dictionary with the keys being nodes and the values being parent nodes. As you visit each vertex (but before processing) you add the parents to the dictionary. Then you can walk up the parent path back to the root vertex.

提交回复
热议问题