title: How do I find a certain node of a binary tree, using recursion?
body: <p>How do I write the code to find a certain node. Specifically how do I say a node was visited after I check it?</p>
  
  <pre><code>public Iterator&lt;T&gt; pathToRoot(T targetElement, BinaryTreeNode&lt;T&gt; current)
          throws ElementNotFoundException
      {
          Stack&lt;BinaryTreeNode&lt;T&gt;&gt; myStack = new Stack&lt;&gt;();
          if (current == null)
              return null;
  
          if (current.element.equals(targetElement)) //found it
          {
              myStack.push(current); //adds the current element to the stack 
          }
              // mark as visited
              //mark node also as found
              // return the found element
  
          if (current.hasLeftChild() || current.hasRightChild()) //if the current node has a left or right child
          {
              // mark node as visited
          }
          if (current.hasLeftChild())//if the current node has a left child node
              pathToRoot(targetElement, current.getLeft()); // check the left child node
  
          if (current.hasRightChild())//same thing as above but for the right
              pathToRoot(targetElement, current.getRight());
  
          if(current != targetElement &amp;&amp; /*node has been visited*/)
              myStack.pop(); // pop node from the stack
  
          return myStack.toString(); //return string of path to root
      }
  </code></pre>
  
  <p>/<em>using a dfs search to find a node</em>/</p>