title: Revisiting some nodes in a recursive function (DFS) over a tree
body: <p>I traverse the nodes of a tree in depth-first manner. Suppose the tree is as follows:
  <img src="https://i.stack.imgur.com/ZD2VK.png" alt="enter image description here"></p>
  
  <p>Now, suppose that I am in node <code>E</code> and for some condition I want to back to the node <code>C</code> and continue from there. Then previous traversing should be canceled and node <code>C</code>, <code>D</code>, <code>E</code> should be evaluated again. Node <code>F</code> and <code>G</code> shouldn't be traversed twice as the previous recursive navigation has been cancelled!</p>
  
  <pre><code>Usual navigation : A B C D E F G
  The desire navigation : A B C D E C D E F G
  </code></pre>
  
  <p>The general code of depth-first traversing is as follows:</p>
  
  <pre><code>void DFS(node x)
  {
      z = evaluate(x);
      // if (z != null) DFS(z) 
      // Z could be a node which has been already traversed, 
      // let's suppose it's an ancestor of x
  
      foreach (node y in c.children)
      {
          DFS(y);
      }
  }
  </code></pre>
  
  <p>Please help me how can I have such navigation in the tree?</p>