Problem in binary tree; need help
<p>can you help me please?  I am making a binary tree with node insertion.  How can I insert the new node to the current node in respect of BST rule?</p>

<p>Example: first the root is empty.</p>

<p>Input number: 50</p>

<p>This will display "Success!"</p>

<p>Insert number: 40</p>

<p>Successfully inserted in the left subtree of 50</p>

<p>insert number: 20</p>

<p>successfully inserted in the left subtree of 40</p>

<p>insert number: 80</p>

<p>successfully inserted in the right subtree of 50</p>

<p>Can you help me please? Thank you in advance hoping for your positive response...</p>

<p>Here's my code:</p>

<pre><code>class Node
{
  public int num;
  public Node llink;
  public Node rlink;
}


public class BinaryTreeOperations
{
  //public Node llink=null;
  // public Node rlink=null;
  private Node temp;
  private Node current;
  private Node root;

  public boolean isEmpty()
  {
    return root==null;
  }


  public void insertNum(int n)
  {

    temp=null;
    current=null;  


    Node newNode = new Node();
    newNode.num=n;
    newNode.llink=null;
    newNode.rlink=null;


    if(isEmpty())
    {
      root=newNode;
      System.out.println("Successfully inserted!");
    }
    else
    {
      temp=root;
      while(temp!=null)
      {
        current = temp;
        root = current;
        temp=null; 
      }

    if(n&lt;current.num)
    {
      current.llink=newNode;
      //current.llink=temp;
      System.out.println("inserted on the left subtree " +current.num);
    }  
    else
    {
      newNode.rlink=newNode; 
      System.out.println("inserted on the right subtree  "+current.num );
    }  
  }
} 
</code></pre>
