
class TreeTwo
{
    TreeNode root ;

    boolean isTreeEmpty()
    {
        return (root==null) ;
    }


    private void printTreeAux(TreeNode tn)
    {
       // given an unprinted node, print the node,
       // recurse on left child, recurse on right child
       // tn can be null
       if ( tn==null ) 
       {
           System.out.println("-") ;
       }
       else
       {
           System.out.println(tn.v) ;
           printTreeAux( tn.lc ) ;
           printTreeAux( tn.rc ) ;
       }
    }

    void printTree()
    {
        printTreeAux(root) ;
    }

    // maybe not stupid ...

    void insertToTree( int value )
    {
System.out.println("enter: insertToTree") ;
        if ( root==null )
        {
System.out.println("insert to empty tree") ;
           root = new TreeNode() ;
           root.v = value ;
           return ;
        }

        // ASSERT: root!=null

        TreeNode tn = root ;
        while( true )
        {
           if ( tn.v<value )
           {
           // go right
System.out.println("going right") ;
               if ( tn.rc==null )
               {
System.out.println("inserting "+value) ;
                   // found the place to insert :-)
                   tn.rc = new TreeNode() ;
                   (tn.rc).v = value ;
                   break ;
               }
               tn = tn.rc ;     
           }
           else
           {
           // go left
System.out.println("going left") ;
               if ( tn.lc==null )
               {
System.out.println("inserting "+value) ;
                   // found the place to insert :-)
                   tn.lc = new TreeNode() ;
                   (tn.lc).v = value ;
                   break ;
               }
               tn = tn.lc ;
           }
        }
    }

}

