
class TreeOne
{
    TreeNode root ;

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


    // 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.data = value ;
           return ;
        }

        // ASSERT: root!=null

        TreeNode tn = root ;
        while( true )
        {
           if ( tn.data<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).data = 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).data = value ;
                   break ;
               }
               tn = tn.lc ;
           }
        }
    }

}

