12 Replies - 953 Views - Last Post: 21 November 2011 - 10:29 PM Rate Topic: -----

#1 gutchman84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 27-March 11

I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 07:27 PM

This is the requirement for the assignment:

Revise the program BinaryTree.java by adding three new methods that enables the duplication of a tree to another.
The following hint is provided.

Hint: Refer to the duplicate( ) method in the BinaryNode.java program. In the duplicate methods you define for the BinaryTree class, consider calling the duplicate( ) method defined in the BinaryNode class.

// BinaryNode class; stores a node in a tree.
//
// CONSTRUCTION: with (a) no parameters, or (B)/> an Object,
//     or (c) an Object, left child, and right child.
//
// *******************PUBLIC OPERATIONS**********************
// int size( )            --> Return size of subtree at node
// int height( )          --> Return height of subtree at node
// void printPostOrder( ) --> Print a postorder tree traversal
// void printInOrder( )   --> Print an inorder tree traversal
// void printPreOrder( )  --> Print a preorder tree traversal
// BinaryNode duplicate( )--> Return a duplicate tree

/**
 * Binary node class with recursive routines to
 * compute size and height.
 */
final class BinaryNode<AnyType>
{
    public BinaryNode( )
    {
        this( null, null, null );
    }
    
    public BinaryNode( AnyType theElement, BinaryNode<AnyType> lt, BinaryNode<AnyType> rt )
    {
        element = theElement;
        left    = lt;
        right   = rt;
    }

    /**
     * Return the size of the binary tree rooted at t.
     */
    public static <AnyType> int size( BinaryNode<AnyType> t )
    {
        if( t == null )
            return 0;
        else
            return 1 + size( t.left ) + size( t.right );
    }

    /**
     * Return the height of the binary tree rooted at t.
     */
    public static <AnyType> int height( BinaryNode<AnyType> t )
    {
        if( t == null )
            return -1;
        else
            return 1 + Math.max( height( t.left ), height( t.right ) );
    }

    // Print tree rooted at current node using preorder traversal.
    public void printPreOrder( )
    {
        System.out.println( element );       // Node
        if( left != null )
            left.printPreOrder( );           // Left
        if( right != null )
            right.printPreOrder( );          // Right
    }


    // Print tree rooted at current node using postorder traversal.
    public void printPostOrder( )
    {
        if( left != null )
            left.printPostOrder( );          // Left
        if( right != null )
            right.printPostOrder( );         // Right
        System.out.println( element );       // Node
    }

    // Print tree rooted at current node using inorder traversal.
    public void printInOrder( )
    {
        if( left != null )
            left.printInOrder( );            // Left
        System.out.println( element );       // Node
        if( right != null )
            right.printInOrder( );           // Right
    }


    /**
     * Return a reference to a node that is the root of a
     * duplicate of the binary tree rooted at the current node.
     */
    public BinaryNode<AnyType> duplicate( )
    {
        BinaryNode<AnyType> root = new BinaryNode<AnyType>( element, null, null );

        if( left != null )            // If there's a left subtree
            root.left = left.duplicate( );    // Duplicate; attach
        if( right != null )          // If there's a right subtree
            root.right = right.duplicate( );  // Duplicate; attach
        return root;                      // Return resulting tree
    }
    
    public AnyType getElement( )
    {
        return element;
    }
    
    public BinaryNode<AnyType> getLeft( )
    {
        return left;
    }
    
    public BinaryNode<AnyType> getRight( )
    {
        return right;
    }
    
    public void setElement( AnyType x )
    {
        element = x;
    }
    
    public void setLeft( BinaryNode<AnyType> t )
    {
        left = t;
    }
    
    public void setRight( BinaryNode<AnyType> t )
    {
        right = t;
    }

    private AnyType             element;
    private BinaryNode<AnyType> left;
    private BinaryNode<AnyType> right;
}



Below is what I've done with the BinaryTree.java file:
// BinaryTree class; stores a binary tree.
//
// CONSTRUCTION: with (a) no parameters or (B)/> an object to
//    be placed in the root of a one-element tree.
//
// *******************PUBLIC OPERATIONS**********************
// Various tree traversals, size, height, isEmpty, makeEmpty.
// Also, the following tricky method:
// void merge( Object root, BinaryTree t1, BinaryTree t2 )
//                        --> Construct a new tree
// *******************ERRORS*********************************
// Error message printed for illegal merges.

/**
 * BinaryTree class that illustrates the calling of
 * BinaryNode recursive routines and merge.
 */
public class BinaryTree<AnyType>
{            
    
    public BinaryTree( )
    {
        root = null;
    }

    public BinaryTree( AnyType rootItem )
    {
        root = new BinaryNode<AnyType>( rootItem, null, null );
    }

    public void printPreOrder( )
    {
        if( root != null )
            root.printPreOrder( );
    }

    public void printInOrder( )
    {
        if( root != null )
           root.printInOrder( );
    }

    public void printPostOrder( )
    {
        if( root != null )
           root.printPostOrder( );
    }

    // added this method
    public BinaryTree<AnyType> duplicateFrom(BinaryTree<Integer> t2)
    {

        
        BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
       
    }

    // added this method
    public BinaryTree<AnyType> duplicate(BinaryTree<Integer> t6)
    {
        BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
    }

    // added this method
    public BinaryTree<AnyType> duplicate()
    {
        BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
    }

    public void makeEmpty( )
    {
        root = null;
    }

    public boolean isEmpty( )
    {
        return root == null;
    }
    
    /**
     * Merge routine for BinaryTree class.
     * Forms a new tree from rootItem, t1 and t2.
     * Does not allow t1 and t2 to be the same.
     * Correctly handles other aliasing conditions.
     */
    public void merge( AnyType rootItem, BinaryTree<AnyType> t1, BinaryTree<AnyType> t2 )
    {
        if( t1.root == t2.root && t1.root != null )
        {
            System.err.println( "leftTree==rightTree; merge aborted" );
            return;
        }

            // Allocate new node
        root = new BinaryNode<AnyType>( rootItem, t1.root, t2.root );

            // Ensure that every node is in one tree
        if( this != t1 )
            t1.root = null;
        if( this != t2 )
            t2.root = null;
    }

    public int size( )
    {
        return BinaryNode.size( root );
    }

    public int height( )
    {
        return BinaryNode.height( root );
    }

    public BinaryNode<AnyType> getRoot( )
    {
        return root;
    }
    
    private BinaryNode<AnyType> root;

   static public void main(String[] args) 
   {
        BinaryTree<Integer> t1 = new BinaryTree<Integer>(1);
        BinaryTree<Integer> t3 = new BinaryTree<Integer>(3);
        BinaryTree<Integer> t5 = new BinaryTree<Integer>(5);
        BinaryTree<Integer> t7 = new BinaryTree<Integer>(7);
        BinaryTree<Integer> t2 = new BinaryTree<Integer>();
        BinaryTree<Integer> t4 = new BinaryTree<Integer>();
        BinaryTree<Integer> t6 = new BinaryTree<Integer>();

        t2.merge(2, t1, t3);
        t6.merge(6, t5, t7);
        BinaryTree<Integer> t8 = new BinaryTree<Integer>();

        t8 = t8.duplicateFrom(t2); //an instance method
        System.out.println("t8 from t2");
        t8.printInOrder();

        t8 = duplicate(t6); // a static method
        System.out.println("t8 from t6");
        t8.printInOrder();

        t4.merge(4, t2, t6);
        t8 = t4.duplicate(); // an instance method
        System.out.println("t8 from t4");
        t8.printInOrder();
    }
}


I'm also attaching a screenshot of the output the working program will yield.
What do I need to do with the 3 methods added in order to get a working program with the proper output? Should I declare some more variables somewhere in the BinaryTree.java file?

Attached File(s)


This post has been edited by smohd: 21 November 2011 - 07:54 PM
Reason for edit:: Code tags added. Please use [code] tags when posting codes


Is This A Good Question/Topic? 0
  • +

Replies To: I have to revise the program BinaryTree.java by adding 3new methods

#2 exiles.prx  Icon User is offline

  • D.I.C Head

Reputation: 65
  • View blog
  • Posts: 241
  • Joined: 22-November 10

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 08:22 PM

Do you have additional details about the assignment? I am a little confused as to what your supposed to do here. Also, I noticed you use netbeans as your IDE. I strongly advise you to NOT use it's GUI builder, even if you get the urge.... uninstall :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#3 gutchman84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 27-March 11

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 08:27 PM

Yes, I just added a little more to my code, here's the BinaryTree.java

// BinaryTree class; stores a binary tree.
//
// CONSTRUCTION: with (a) no parameters or (B)/> an object to
//    be placed in the root of a one-element tree.
//
// *******************PUBLIC OPERATIONS**********************
// Various tree traversals, size, height, isEmpty, makeEmpty.
// Also, the following tricky method:
// void merge( Object root, BinaryTree t1, BinaryTree t2 )
//                        --> Construct a new tree
// *******************ERRORS*********************************
// Error message printed for illegal merges.

/**
 * BinaryTree class that illustrates the calling of
 * BinaryNode recursive routines and merge.
 */
public class BinaryTree<AnyType>
{

    
    
    
    
    public BinaryTree( )
    {
        root = null;
    }

    public BinaryTree( AnyType rootItem )
    {
        root = new BinaryNode<AnyType>( rootItem, null, null );
    }

    public void printPreOrder( )
    {
        if( root != null )
            root.printPreOrder( );
    }

    public void printInOrder( )
    {
        if( root != null )
           root.printInOrder( );
    }

    public void printPostOrder( )
    {
        if( root != null )
           root.printPostOrder( );
    }

    // added this method
    public BinaryTree<AnyType> duplicateFrom(BinaryTree<Integer> t2)
    {
        BinaryTree<AnyType> duplicate = new BinaryTree<AnyType>(); 
        
        //BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
       
    }

    // added this method
    public BinaryTree<AnyType> duplicate(BinaryTree<Integer> t6)
    {
        BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
    }

    // added this method
    public BinaryTree<AnyType> duplicate()
    {
        BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
    }

    public void makeEmpty( )
    {
        root = null;
    }

    public boolean isEmpty( )
    {
        return root == null;
    }
    
    /**
     * Merge routine for BinaryTree class.
     * Forms a new tree from rootItem, t1 and t2.
     * Does not allow t1 and t2 to be the same.
     * Correctly handles other aliasing conditions.
     */
    public void merge( AnyType rootItem, BinaryTree<AnyType> t1, BinaryTree<AnyType> t2 )
    {
        if( t1.root == t2.root && t1.root != null )
        {
            System.err.println( "leftTree==rightTree; merge aborted" );
            return;
        }

            // Allocate new node
        root = new BinaryNode<AnyType>( rootItem, t1.root, t2.root );

            // Ensure that every node is in one tree
        if( this != t1 )
            t1.root = null;
        if( this != t2 )
            t2.root = null;
    }

    public int size( )
    {
        return BinaryNode.size( root );
    }

    public int height( )
    {
        return BinaryNode.height( root );
    }

    public BinaryNode<AnyType> getRoot( )
    {
        return root;
    }
    
    private BinaryNode<AnyType> root;

   static public void main(String[] args) 
   {
        BinaryTree<Integer> t1 = new BinaryTree<Integer>(1);
        BinaryTree<Integer> t3 = new BinaryTree<Integer>(3);
        BinaryTree<Integer> t5 = new BinaryTree<Integer>(5);
        BinaryTree<Integer> t7 = new BinaryTree<Integer>(7);
        BinaryTree<Integer> t2 = new BinaryTree<Integer>();
        BinaryTree<Integer> t4 = new BinaryTree<Integer>();
        BinaryTree<Integer> t6 = new BinaryTree<Integer>();

        t2.merge(2, t1, t3);
        t6.merge(6, t5, t7);
        BinaryTree<Integer> t8 = new BinaryTree<Integer>();

        t8 = t8.duplicateFrom(t2); //an instance method
        System.out.println("t8 from t2");
        t8.printInOrder();

        t8 = duplicate(t6); // a static method
        System.out.println("t8 from t6");
        t8.printInOrder();

        t4.merge(4, t2, t6);
        t8 = t4.duplicate(); // an instance method
        System.out.println("t8 from t4");
        t8.printInOrder();
    }

    

}




These are the errors that I get:

E:\UHCL Fall 2011\Data Structures\BinaryTree\src\BinaryTree.java:146: non-static method duplicate(BinaryTree<java.lang.Integer>) cannot be referenced from a static context
t8 = duplicate(t6); // a static method
E:\UHCL Fall 2011\Data Structures\BinaryTree\src\BinaryTree.java:146: incompatible types
found : BinaryTree<AnyType>
required: BinaryTree<java.lang.Integer>
t8 = duplicate(t6); // a static method
2 errors

Any suggestions on how to fix these errors?
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 08:33 PM

public BinaryTree<AnyType> duplicate(BinaryTree<Integer> t6)

is not defined as static
Was This Post Helpful? 0
  • +
  • -

#5 gutchman84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 27-March 11

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 08:39 PM

OK I just defined it as static. Here's the code now:

// BinaryTree class; stores a binary tree.
//
// CONSTRUCTION: with (a) no parameters or (B)/> an object to
//    be placed in the root of a one-element tree.
//
// *******************PUBLIC OPERATIONS**********************
// Various tree traversals, size, height, isEmpty, makeEmpty.
// Also, the following tricky method:
// void merge( Object root, BinaryTree t1, BinaryTree t2 )
//                        --> Construct a new tree
// *******************ERRORS*********************************
// Error message printed for illegal merges.

/**
 * BinaryTree class that illustrates the calling of
 * BinaryNode recursive routines and merge.
 */
public class BinaryTree<AnyType>
{

    
    
    
    
    public BinaryTree( )
    {
        root = null;
    }

    public BinaryTree( AnyType rootItem )
    {
        root = new BinaryNode<AnyType>( rootItem, null, null );
    }

    public void printPreOrder( )
    {
        if( root != null )
            root.printPreOrder( );
    }

    public void printInOrder( )
    {
        if( root != null )
           root.printInOrder( );
    }

    public void printPostOrder( )
    {
        if( root != null )
           root.printPostOrder( );
    }

    // added this method
    public BinaryTree<AnyType> duplicateFrom(BinaryTree<Integer> t2)
    {
        BinaryTree<AnyType> duplicate = new BinaryTree<AnyType>();
        
        //BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
       
    }

    // added this method
    public static BinaryTree<AnyType> duplicate(BinaryTree<Integer> t6)
    {
        BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
    }

    // added this method
    public BinaryTree<AnyType> duplicate()
    {
        BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
    }

    public void makeEmpty( )
    {
        root = null;
    }

    public boolean isEmpty( )
    {
        return root == null;
    }
    
    /**
     * Merge routine for BinaryTree class.
     * Forms a new tree from rootItem, t1 and t2.
     * Does not allow t1 and t2 to be the same.
     * Correctly handles other aliasing conditions.
     */
    public void merge( AnyType rootItem, BinaryTree<AnyType> t1, BinaryTree<AnyType> t2 )
    {
        if( t1.root == t2.root && t1.root != null )
        {
            System.err.println( "leftTree==rightTree; merge aborted" );
            return;
        }

            // Allocate new node
        root = new BinaryNode<AnyType>( rootItem, t1.root, t2.root );

            // Ensure that every node is in one tree
        if( this != t1 )
            t1.root = null;
        if( this != t2 )
            t2.root = null;
    }

    public int size( )
    {
        return BinaryNode.size( root );
    }

    public int height( )
    {
        return BinaryNode.height( root );
    }

    public BinaryNode<AnyType> getRoot( )
    {
        return root;
    }
    
    private BinaryNode<AnyType> root;

   static public void main(String[] args) 
   {
        BinaryTree<Integer> t1 = new BinaryTree<Integer>(1);
        BinaryTree<Integer> t3 = new BinaryTree<Integer>(3);
        BinaryTree<Integer> t5 = new BinaryTree<Integer>(5);
        BinaryTree<Integer> t7 = new BinaryTree<Integer>(7);
        BinaryTree<Integer> t2 = new BinaryTree<Integer>();
        BinaryTree<Integer> t4 = new BinaryTree<Integer>();
        BinaryTree<Integer> t6 = new BinaryTree<Integer>();

        t2.merge(2, t1, t3);
        t6.merge(6, t5, t7);
        BinaryTree<Integer> t8 = new BinaryTree<Integer>();

        t8 = t8.duplicateFrom(t2); //an instance method
        System.out.println("t8 from t2");
        t8.printInOrder();

        t8 = duplicate(t6); // a static method
        System.out.println("t8 from t6");
        t8.printInOrder();

        t4.merge(4, t2, t6);
        t8 = t4.duplicate(); // an instance method
        System.out.println("t8 from t4");
        t8.printInOrder();
    }

    

}



And now my errors are as follows:

E:\UHCL Fall 2011\Data Structures\BinaryTree\src\BinaryTree.java:64: non-static class AnyType cannot be referenced from a static context
public static BinaryTree<AnyType> duplicate(BinaryTree<Integer> t6)
E:\UHCL Fall 2011\Data Structures\BinaryTree\src\BinaryTree.java:66: non-static class AnyType cannot be referenced from a static context
BinaryTree<AnyType> duplicate = duplicate();
E:\UHCL Fall 2011\Data Structures\BinaryTree\src\BinaryTree.java:66: non-static method duplicate() cannot be referenced from a static context
BinaryTree<AnyType> duplicate = duplicate();
3 errors
Was This Post Helpful? 0
  • +
  • -

#6 exiles.prx  Icon User is offline

  • D.I.C Head

Reputation: 65
  • View blog
  • Posts: 241
  • Joined: 22-November 10

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 08:42 PM

When using static you have to format the function call like so:

className.functionName();

This post has been edited by exiles.prx: 21 November 2011 - 08:43 PM

Was This Post Helpful? 0
  • +
  • -

#7 gutchman84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 27-March 11

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 08:54 PM

This is what the method looks like now:

public static BinaryTree<AnyType> duplicate(BinaryTree<Integer> t6)
{
BinaryTree.duplicate();

}

Is this what you mean? Should I do something with "AnyType" in the method definition here?
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 08:55 PM

View Postexiles.prx, on 21 November 2011 - 11:42 PM, said:

When using static you have to format the function call like so:

className.functionName();

True if you call it from another class
The main() class is in the class BinaryTree so it should work
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 09:01 PM

You cannot have a reference like that

public static BinaryTree<AnyType>

The <AnyType> is determined by calling the constructor
a static method belongs to the class not to an instance of the class

If you make

BinaryTree<Integer> bi = new BinaryTree<Integer>();
BinaryTree<String> bs = new BinatryTree<String>();

then duplicate should return a BinaryTree<Integer> or a BinaryTree<String> ???

so you can't <AnyType> on a static method. Hope it is clear
Was This Post Helpful? 0
  • +
  • -

#10 exiles.prx  Icon User is offline

  • D.I.C Head

Reputation: 65
  • View blog
  • Posts: 241
  • Joined: 22-November 10

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 09:05 PM

I was actually talking about the call within main.

View Postgutchman84, on 21 November 2011 - 08:54 PM, said:

This is what the method looks like now:

public static BinaryTree<AnyType> duplicate(BinaryTree<Integer> t6)
{
BinaryTree.duplicate();

}

Is this what you mean? Should I do something with "AnyType" in the method definition here?




@ pbl Really, I could of sworn even in main you still need the class name. Haven't coded in java for months, so maybe its just a habit I gained for clarity and not my java skills fading.
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8346
  • View blog
  • Posts: 31,908
  • Joined: 06-March 08

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 09:12 PM

I agree with you it is a good practice :)
But not related to the @OP problem

public static void main() is a static method of the class where it is located as any other static method in the same class. And those static methods can call each other without having the prefix their name with the classsname.
Was This Post Helpful? 1
  • +
  • -

#12 gutchman84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 27-March 11

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 09:32 PM

I didn't mention this, but I'm not supposed to change the main() method in this assignment. That being said, do you have any suggestions on how I can get my program working right? BTW I don't have anymore errors, and this is my code right now:

// BinaryTree class; stores a binary tree.
//
// CONSTRUCTION: with (a) no parameters or (B)/> an object to
//    be placed in the root of a one-element tree.
//
// *******************PUBLIC OPERATIONS**********************
// Various tree traversals, size, height, isEmpty, makeEmpty.
// Also, the following tricky method:
// void merge( Object root, BinaryTree t1, BinaryTree t2 )
//                        --> Construct a new tree
// *******************ERRORS*********************************
// Error message printed for illegal merges.

/**
 * BinaryTree class that illustrates the calling of
 * BinaryNode recursive routines and merge.
 */
public class BinaryTree<AnyType>
{

    
    
    
    
    public BinaryTree( )
    {
        root = null;
    }

    public BinaryTree( AnyType rootItem )
    {
        root = new BinaryNode<AnyType>( rootItem, null, null );
    }

    public void printPreOrder( )
    {
        if( root != null )
            root.printPreOrder( );
    }

    public void printInOrder( )
    {
        if( root != null )
           root.printInOrder( );
    }

    public void printPostOrder( )
    {
        if( root != null )
           root.printPostOrder( );
    }

    // added this method
    public BinaryTree<AnyType> duplicateFrom(BinaryTree<Integer> t2)
    {
        BinaryTree<AnyType> duplicate = new BinaryTree<AnyType>();
        
        //BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
       
    }

    // added this method
    public static BinaryTree duplicate(BinaryTree<Integer> t6)
    {
        BinaryTree<Integer> bi = new BinaryTree<Integer>();
        //BinaryTree<String> bs = new BinatryTree<String>();
        return (BinaryTree) bi;
    }

    // added this method
    public BinaryTree<AnyType> duplicate()
    {
        BinaryTree<AnyType> duplicate = duplicate();
        return duplicate;
    }

    public void makeEmpty( )
    {
        root = null;
    }

    public boolean isEmpty( )
    {
        return root == null;
    }
    
    /**
     * Merge routine for BinaryTree class.
     * Forms a new tree from rootItem, t1 and t2.
     * Does not allow t1 and t2 to be the same.
     * Correctly handles other aliasing conditions.
     */
    public void merge( AnyType rootItem, BinaryTree<AnyType> t1, BinaryTree<AnyType> t2 )
    {
        if( t1.root == t2.root && t1.root != null )
        {
            System.err.println( "leftTree==rightTree; merge aborted" );
            return;
        }

            // Allocate new node
        root = new BinaryNode<AnyType>( rootItem, t1.root, t2.root );

            // Ensure that every node is in one tree
        if( this != t1 )
            t1.root = null;
        if( this != t2 )
            t2.root = null;
    }

    public int size( )
    {
        return BinaryNode.size( root );
    }

    public int height( )
    {
        return BinaryNode.height( root );
    }

    public BinaryNode<AnyType> getRoot( )
    {
        return root;
    }
    
    private BinaryNode<AnyType> root;

   static public void main(String[] args) 
   {
        BinaryTree<Integer> t1 = new BinaryTree<Integer>(1);
        BinaryTree<Integer> t3 = new BinaryTree<Integer>(3);
        BinaryTree<Integer> t5 = new BinaryTree<Integer>(5);
        BinaryTree<Integer> t7 = new BinaryTree<Integer>(7);
        BinaryTree<Integer> t2 = new BinaryTree<Integer>();
        BinaryTree<Integer> t4 = new BinaryTree<Integer>();
        BinaryTree<Integer> t6 = new BinaryTree<Integer>();

        t2.merge(2, t1, t3);
        t6.merge(6, t5, t7);
        BinaryTree<Integer> t8 = new BinaryTree<Integer>();

        t8 = t8.duplicateFrom(t2); //an instance method
        System.out.println("t8 from t2");
        t8.printInOrder();

        t8 = duplicate(t6); // a static method
        System.out.println("t8 from t6");
        t8.printInOrder();

        t4.merge(4, t2, t6);
        t8 = t4.duplicate(); // an instance method
        System.out.println("t8 from t4");
        t8.printInOrder();
    }

    

}



But when I run the program this is the output:

run:
t8 from t2
t8 from t6
Exception in thread "main" java.lang.StackOverflowError
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
at BinaryTree.duplicate(BinaryTree.java:74)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)

How can I fix this problem?
Was This Post Helpful? 0
  • +
  • -

#13 gutchman84  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 34
  • Joined: 27-March 11

Re: I have to revise the program BinaryTree.java by adding 3new methods

Posted 21 November 2011 - 10:29 PM

Well my program now has no errors or exceptions, but it's still not working properly
Here is the binaryTree code now

Here is the BinaryNode java file:
// BinaryNode class; stores a node in a tree.
//
// CONSTRUCTION: with (a) no parameters, or (B)/> an Object,
//     or (c) an Object, left child, and right child.
//
// *******************PUBLIC OPERATIONS**********************
// int size( )            --> Return size of subtree at node
// int height( )          --> Return height of subtree at node
// void printPostOrder( ) --> Print a postorder tree traversal
// void printInOrder( )   --> Print an inorder tree traversal
// void printPreOrder( )  --> Print a preorder tree traversal
// BinaryNode duplicate( )--> Return a duplicate tree

/**
 * Binary node class with recursive routines to
 * compute size and height.
 */
final class BinaryNode<AnyType>
{
    public BinaryNode( )
    {
        this( null, null, null );
    }
    
    public BinaryNode( AnyType theElement, BinaryNode<AnyType> lt, BinaryNode<AnyType> rt )
    {
        element = theElement;
        left    = lt;
        right   = rt;
    }

    /**
     * Return the size of the binary tree rooted at t.
     */
    public static <AnyType> int size( BinaryNode<AnyType> t )
    {
        if( t == null )
            return 0;
        else
            return 1 + size( t.left ) + size( t.right );
    }

    /**
     * Return the height of the binary tree rooted at t.
     */
    public static <AnyType> int height( BinaryNode<AnyType> t )
    {
        if( t == null )
            return -1;
        else
            return 1 + Math.max( height( t.left ), height( t.right ) );
    }

    // Print tree rooted at current node using preorder traversal.
    public void printPreOrder( )
    {
        System.out.println( element );       // Node
        if( left != null )
            left.printPreOrder( );           // Left
        if( right != null )
            right.printPreOrder( );          // Right
    }


    // Print tree rooted at current node using postorder traversal.
    public void printPostOrder( )
    {
        if( left != null )
            left.printPostOrder( );          // Left
        if( right != null )
            right.printPostOrder( );         // Right
        System.out.println( element );       // Node
    }

    // Print tree rooted at current node using inorder traversal.
    public void printInOrder( )
    {
        if( left != null )
            left.printInOrder( );            // Left
        System.out.println( element );       // Node
        if( right != null )
            right.printInOrder( );           // Right
    }


    /**
     * Return a reference to a node that is the root of a
     * duplicate of the binary tree rooted at the current node.
     */
    public BinaryNode<AnyType> duplicate( )
    {
        BinaryNode<AnyType> root = new BinaryNode<AnyType>( element, null, null );

        if( left != null )            // If there's a left subtree
            root.left = left.duplicate( );    // Duplicate; attach
        if( right != null )          // If there's a right subtree
            root.right = right.duplicate( );  // Duplicate; attach
        return root;                      // Return resulting tree
    }
    
    public AnyType getElement( )
    {
        return element;
    }
    
    public BinaryNode<AnyType> getLeft( )
    {
        return left;
    }
    
    public BinaryNode<AnyType> getRight( )
    {
        return right;
    }
    
    public void setElement( AnyType x )
    {
        element = x;
    }
    
    public void setLeft( BinaryNode<AnyType> t )
    {
        left = t;
    }
    
    public void setRight( BinaryNode<AnyType> t )
    {
        right = t;
    }

    private AnyType             element;
    private BinaryNode<AnyType> left;
    private BinaryNode<AnyType> right;
}



// BinaryTree class; stores a binary tree.
//
// CONSTRUCTION: with (a) no parameters or (B)/> an object to
//    be placed in the root of a one-element tree.
//
// *******************PUBLIC OPERATIONS**********************
// Various tree traversals, size, height, isEmpty, makeEmpty.
// Also, the following tricky method:
// void merge( Object root, BinaryTree t1, BinaryTree t2 )
//                        --> Construct a new tree
// *******************ERRORS*********************************
// Error message printed for illegal merges.

/**
 * BinaryTree class that illustrates the calling of
 * BinaryNode recursive routines and merge.
 */
public class BinaryTree<AnyType>
{

    
    
    
    
    public BinaryTree( )
    {
        root = null;
    }

    public BinaryTree( AnyType rootItem )
    {
        root = new BinaryNode<AnyType>( rootItem, null, null );
    }

    public void printPreOrder( )
    {
        if( root != null )
            root.printPreOrder( );
    }

    public void printInOrder( )
    {
        if( root != null )
           root.printInOrder( );
    }

    public void printPostOrder( )
    {
        if( root != null )
           root.printPostOrder( );
    }

    // added this method
    public BinaryTree<AnyType> duplicateFrom(BinaryTree<Integer> t2)
    {
        BinaryTree<AnyType> duplicate = new BinaryTree<AnyType>();
        return duplicate;
       
    }

    // added this method
    public static BinaryTree duplicate(BinaryTree<Integer> t6)
    {
        BinaryTree<Integer> bi = new BinaryTree<Integer>();
        return (BinaryTree) bi;
    }

    // added this method
    public BinaryTree<AnyType> duplicate()
    {
        //BinaryTree<AnyType> duplicate = duplicate();
         BinaryTree<AnyType> duplicate = new BinaryTree<AnyType>();
        return duplicate;
    }

    public void makeEmpty( )
    {
        root = null;
    }

    public boolean isEmpty( )
    {
        return root == null;
    }
    
    /**
     * Merge routine for BinaryTree class.
     * Forms a new tree from rootItem, t1 and t2.
     * Does not allow t1 and t2 to be the same.
     * Correctly handles other aliasing conditions.
     */
    public void merge( AnyType rootItem, BinaryTree<AnyType> t1, BinaryTree<AnyType> t2 )
    {
        if( t1.root == t2.root && t1.root != null )
        {
            System.err.println( "leftTree==rightTree; merge aborted" );
            return;
        }

            // Allocate new node
        root = new BinaryNode<AnyType>( rootItem, t1.root, t2.root );

            // Ensure that every node is in one tree
        if( this != t1 )
            t1.root = null;
        if( this != t2 )
            t2.root = null;
    }

    public int size( )
    {
        return BinaryNode.size( root );
    }

    public int height( )
    {
        return BinaryNode.height( root );
    }

    public BinaryNode<AnyType> getRoot( )
    {
        return root;
    }
    
    private BinaryNode<AnyType> root;

   static public void main(String[] args) 
   {
        BinaryTree<Integer> t1 = new BinaryTree<Integer>(1);
        BinaryTree<Integer> t3 = new BinaryTree<Integer>(3);
        BinaryTree<Integer> t5 = new BinaryTree<Integer>(5);
        BinaryTree<Integer> t7 = new BinaryTree<Integer>(7);
        BinaryTree<Integer> t2 = new BinaryTree<Integer>();
        BinaryTree<Integer> t4 = new BinaryTree<Integer>();
        BinaryTree<Integer> t6 = new BinaryTree<Integer>();

        t2.merge(2, t1, t3);
        t6.merge(6, t5, t7);
        BinaryTree<Integer> t8 = new BinaryTree<Integer>();

        t8 = t8.duplicateFrom(t2); //an instance method
        System.out.println("t8 from t2");
        t8.printInOrder();

        t8 = duplicate(t6); // a static method
        System.out.println("t8 from t6");
        t8.printInOrder();

        t4.merge(4, t2, t6);
        t8 = t4.duplicate(); // an instance method
        System.out.println("t8 from t4");
        t8.printInOrder();
    }

    

}



And this is the output without the node numbers:

t8 from t2
t8 from t6
t8 from t4

What should I do to get node numbers to print? Should I add more variables and println statements to each of the three methods?

Here is the hint given in this assignment description:
Hint: Refer to the duplicate( ) method in the BinaryNode.java program. In the duplicate methods you define for the BinaryTree class, consider calling the duplicate( ) method defined in the BinaryNode class.



The correct output should be like this:
t8 from t2
1
2
3
t8 from t6
5
6
7
t8 from t4
1
2
3
4
5
6
7
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1