
class TreeThree
{
    TreeNode root ;

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


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

    static final int INDENT_AMOUNT = 5 ;

    void indentByLevel( int level ) 
    {
       int nos = level * INDENT_AMOUNT ;
       for (int i=0;i<nos;i++) System.out.print(" ") ;
    }

    void printTree()
    {
        printTreeAux(root,0) ;
    }

    void insertToTree( int value )
    {
        if ( root==null )
        {
           root = new TreeNode() ;
           root.v = value ;
           return ;
        }

        // ASSERT: root!=null

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

}

