title: Java - Mirror Image of a binary tree using recursion
body: <p>I'm writing a mirror image method for a binary tree.  The way my class works is I have an abstract class BinaryTree, with subclasses EmptyTree and ConsTree.  I'm having trouble writing the method for the ConsTree.  The class looks something like this:</p>
  
  <pre><code>public class ConsTree&lt;T&gt; extends BinaryTree&lt;T&gt;
  {
      BinaryTree&lt;T&gt; left;
      BinaryTree&lt;T&gt; right;
      T data;
  
      public BinaryTree&lt;T&gt; mirrorImage() 
      {
          ConsTree&lt;T&gt; tree = new ConsTree&lt;T&gt;(this.data, this.right, this.left); //In the constructor, the second parameter sets the left tree, so creates a new tree with the left and right trees swapped
          if(this.left == null &amp;&amp; this.right == null)
                  return tree;
          if(this.left == null)
                  return tree + this.right.mirrorImage();
          else if(right == null)
                  return tree + this.left.mirrorImage();
  
          return tree + this.left.mirrorImage() + this.right.mirrorImage();
  }
  </code></pre>
  
  <p>Obviously this doesn't work because I can't use a '+' operator with BinaryTree objects, however this is the basic idea of what I want to accomplish.  I'm just a little confused with how to combine the trees together.  Any help is appreciated.  Thanks.</p>