title: C# Graph Traversal
body: <p>This algorithm does a great job of traversing the nodes in a graph.</p>
  
  <pre><code>Dictionary&lt;Node, bool&gt; visited = new Dictionary&lt;Node, bool&gt;();
  
  Queue&lt;Node&gt; worklist = new Queue&lt;Node&gt;();
  
  visited.Add(this, false);
  
  worklist.Enqueue(this);
  
  while (worklist.Count != 0)
  {
      Node node = worklist.Dequeue();
  
      foreach (Node neighbor in node.Neighbors)
      {
          if (!visited.ContainsKey(neighbor))
          {
              visited.Add(neighbor, false);
              worklist.Enqueue(neighbor);
          }
      }
  }
  </code></pre>
  
  <p>I can use this to find a target node in the graph.  The worklist dequeues (or pops) the items as the worklist is processed.  Once I find the target how can I return the full path to the node?  </p>
  
  <p><strong>Update</strong>
  I am trying to figure out how to reverse the path to the root.  The method is called on the root node, after that, children may have two parents, so it isn't as simple as calling the parent property on each node and traversing back up.</p>
  
  <p>The goal of the method is to find the path, not to iterate all nodes, or to check if a node does exist.    </p>