### height

#### Binary Tree find height of a specific Node

```Hello guys I am stack somewhere so this is my question...
I got the following binary tree class
public class BTree
{
private TreeNode root;
int i = 0;
/////////////////////
public BTree()
{
root = null;
}
}
and my TreeNode class
public class TreeNode
{
private TreeNode left; //consider public
private int number; //
private TreeNode right; //////////////////
//////////////////////
public TreeNode(int number)
{
this.number = number;
left = null;
right = null;
}
....
}
and I need to build a method that could count Tree height till a specific data
inside a Node. For Example: int height = tree.height(5);
(to find the height of the Node that contains number 5)
I am in the part :
public int height(int number)
{
return countHeight(root, number);
}
private int countHeight(TreeNode node, int number)
{
if(node != null && node.getNumber() == number)
return 0;
return //what should I write here?
}
Recursive methods is a little hard for me so I would like
a little help over here.
Thnx in advance...
```
```I just wrote this code and it seems to work properly.
If you got any better solution feel free to share.
public int height(int number) /// it could be Object
{
return countHeight(root, number);
}
private int countHeight(TreeNode node, int number)
{
if(node != null && node.getNumber() == number)
return 1;
if(number < node.getNumber())
return countHeight(node.getLeft()) + 1;
else
return countHeight(node.getRight()) + 1;
}```

### Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App