Detecting if a node in a tree has child(s) or child nodes have been visited
<p>I am struggling with the logic behind detecting nodes in my tree exists or have been visited. </p>

<p>I have a tree with nodes (a node has a left and right child node).</p>

<p>I want to check 2 things on a node:
If there are no child nodes
If there are child(s) nodes I want to check if they have been visited.</p>

<p>I currently have a large condition which I hate the look of. Is there a way I can simplify it?            </p>

<pre><code>public boolean finished(){
      return right == null &amp;&amp; left == null || ((right != null &amp;&amp; right.visited &amp;&amp; (left != null &amp;&amp; left.visited))
}
</code></pre>

<p>I want <code>finished()</code> to be true:
If a right and left node dont exist
If a right exists and has been visited
If a left exists and has been visited</p>

<p>I think I also need an <code>OR</code> so if a right exists <code>AND</code> visited <code>AND</code> left is null</p>

<p>I'm a bit confused :S</p>
