title: Intersection of 2 binary search trees
body: <p>Hey, So I want to create a new tree which is basically the intersection (mathematical definition of intersection) of 2 given binary search trees. I have a method that prints out all the nodes at a particular level of the tree and I have a method that can find out the depth of the tree.I am pasting my work so far though it is incomplete and I'm stuck with the logic.Help will be appreciated.</p>
  
  <pre><code>    public static Bst&lt;Customer&gt; intersect (Bst&lt;Customer&gt; a, Bst&lt;Customer&gt; b){
      Bst&lt;Customer&gt; result = new Bst&lt;Customer&gt;();
      BTNode&lt;Customer&gt; cur1;
      BTNode&lt;Customer&gt; cur2;
      BTNode&lt;Customer&gt; cur3;
      cur1=a.root;
      cur2=b.root;
      cur3=result.root;
      int Resultdepth;
      if(a.maxDepth()&lt;b.maxDepth())
          Resultdepth=a.maxDepth();
      else
          Resultdepth=b.maxDepth();
  
      if(cur1==null || cur2==null){ // Handeling the root case intially
          result = null;
      }
      else 
        cur3.item.set_account_id(cur1.item.get_accountid()+ cur2.item.get_accountid());
  
      cur1=cur1.left;
      cur2=cur2.left;
      cur3=cur3.left;       
  
      while(&lt;some check&gt;){
  
      }
  
  
      return result;
  
  }
  
  
      public int maxDepth(){
          return mD(root);
      }
  
      int mD(BTNode&lt;E&gt; node){
         if (node==null) {
              return(0);
          }
         else {
              int lDepth = mD(node.left);
              int rDepth = mD(node.right);
              // use the larger + 1
              return(Math.max(lDepth, rDepth) + 1);
          }
      }
  
       // for printing the nodes at a particular level and giving the starting level
        public void PrintAt(BTNode&lt;E&gt; cur, int level, int desiredLevel) {
           if (cur == null) {
              return;
          }
           if (level == desiredLevel) {
               System.out.print(cur.item.toString() + "");
            }
           else {
               PrintAt(cur.left, level+1, desiredLevel);
               PrintAt(cur.right, level+1, desiredLevel);
            }
  }
  </code></pre>