hello please help me how can i get the height of the tree?I really don't have idea how to get this can you help me please thank you in advance hoping for your positive response...here is my code
private Node root;
public boolean isEmpty()
{
return root==null;
}
public void insertNum(int n)
{
Node temp=null;
Node current=null;
Node newNode = new Node();
newNode.num=n;
if(isEmpty())
{
root=newNode;
System.out.println("Successfully inserted!");
return;
}
temp=root;
while(temp!=null)
{
if(temp.num==n)
{
return;
}
if(temp.num<n)
{
current=temp;
if(temp.rlink==null)
{
temp.rlink=newNode;
System.out.println("Inserted at the right= "+current.num);
}
else
{
temp=temp.rlink;
}
}
else
{
current=temp;
if(temp.llink==null)
{
temp.llink=newNode;
System.out.println("Inserted at the left= "+current.num);
}
else
{
temp=temp.llink;
}
}
}
}