title: Method that returns BinaryTree according to preorder traversal
body: <p>The problem I have is to write a method with the signature</p>
  
  <pre><code>public static BinaryTree generate(BinaryTree root)
  </code></pre>
  
  <p>(it's possible to add other parameters)</p>
  
  <p>This method has to return a <code>BinaryTree</code> like given as parameter (same size and so on), it is needed only to change values in its nodes. Each node of the resulting tree has to have a value equal to the position the equivalent node was processed when we use preorder traversal on <code>root</code>. We start counting with 1.</p>
  
  <pre><code>public class BinaryTree {
      public int value;
      public BinaryTree left;
      public BinaryTree right;
  
      public BinaryTree(int value, BinaryTree left, BinaryTree right)
      {
          this.value = value;
          this.left = left;
          this.right = right;
      }
  }
  </code></pre>
  
  <p>I tried the below, but it doesn't work correctly.</p>
  
  <pre><code>public static BinaryTree preOrder(BinaryTree root, int num)
  {
      //We ALWAYS give 1 as num value!!
      if (root == null)
          return null;
  
      root.value = num;       
      preOrder(root.left, ++num);         
      preOrder(root.right, ++num);
  
      return root;
  }
  </code></pre>
  
  <p>For example, if we have a BinaryTree:</p>
  
  <pre><code>             3
           /      \
         2           1
      /     \
    1         0
  </code></pre>
  
  <p>(It doesn't matter what values there are in the nodes!)</p>
  
  <p>Our method has to return this tree:</p>
  
  <pre><code>             1
           /      \
         2           5
      /     \
    3         4
  </code></pre>