title: Breadth-first graph search with multiple entry and exit points
body: <p>I am trying to make an adjacent list for a directed graph, while the graph has multiple entry and exit points. In the graph the Nodes would be things like AND, OR, NOT, XOR, etc. and the Entry and Exit points will be a single bit (0 or 1).</p>
  
  <p>I've got the following Nodes:</p>
  
  <ul>
  <li>Entry A: 1</li>
  <li>Entry B: 1</li>
  <li>Entry C: 0</li>
  <li>Exit D: ?</li>
  <li>Exit E: ?</li>
  <li>Node1: OR</li>
  <li>Node2: AND</li>
  <li>Node3: AND</li>
  <li>Node4: NOT</li>
  <li>Node5: AND</li>
  <li>Node6: OR</li>
  <li>Node7: NOT</li>
  <li>Node8: NOT</li>
  <li>Node9: AND</li>
  <li>Node10: AND</li>
  <li>Node11: OR</li>
  </ul>
  
  <p>And the following connections between them:</p>
  
  <ul>
  <li>Entry A: Node1, Node2</li>
  <li>Entry B: Node1, Node2</li>
  <li>Entry C: Node3, Node7, Node10</li>
  <li>Node1: Node3, Node5</li>
  <li>Node2: Node4, Node6</li>
  <li>Node3: Node6</li>
  <li>Node4: Node5</li>
  <li>Node5: Node8, Node9</li>
  <li>Node6: Exit D</li>
  <li>Node7: Node9</li>
  <li>Node8: Node10</li>
  <li>Node9: Node11</li>
  <li>Node10: Node11:</li>
  <li>Node11: Exit E</li>
  </ul>
  
  <p>Picture:</p>
  
  <p><img src="https://i.stack.imgur.com/6eWEy.png" alt="Graph of circuit in question"></p>
  
  <p>So now I need to calculate the bytes at the exits of D and E, by following the path of the directed graph.</p>
  
  <p>I found a link of a breath-first graph search with single entry and exit points here:<br>
  <a href="https://stackoverflow.com/questions/58306/graph-algorithm-to-find-all-connections-between-two-arbitrary-vertices/58446#58446">Graph Algorithm To Find All Connections Between Two Arbitrary Vertices</a>.</p>
  
  <p>How can I adapt this breath-first graph search in the link so I can have multiple entry and exit points, and at the same time remove/change the recursive part (since I'm getting <code>StackOverflowError</code>s when using the code in the link above, even when I only have 1 entry and exit point).</p>