title: Algorithm for traversing directed graph like this (picture inside)
body: <p>I have a graph like this:</p>
  
  <p><img src="https://i.stack.imgur.com/auOrj.jpg" alt="graph"></p>
  
  <p>One simple rule:<br>
  Every node in the graph only knows about its successor.</p>
  
  <p>As you can see, the problem occurs when we came to <code>6</code> (by the first branch, <code>1 → 6</code>), so that we do not know when it is time to stop and start traversing another branch (<code>2 → 6</code>).</p>
  
  <p>Could anyone suggest an algorithm for traversing graph like this, please?</p>
  
  <p>I came up with the idea when I am traversing <code>1 → 6 → end of graph</code>, and then returning to <code>2 → 6</code>.<br>
  But I think this is not good idea, because there could be a lot of forks on the <code>1 → 6 → end of graph</code> way.</p>