-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheightBTree.java
More file actions
39 lines (32 loc) · 832 Bytes
/
heightBTree.java
File metadata and controls
39 lines (32 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.io.*;
import java.util.*;
import java.lang.*;
class Node{
int data;
Node left;
Node right;
Node(int k){
data=k;
left=null;
right=null;
}
}
public class BTreeHeight{
public static int height(Node root){
if(root==null)
return 0;
return Math.max(height(root.left),height(root.right))+1;
}
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
Node root = new Node(10);
root.left = new Node(20);
root.right = new Node(30);
root.left.left = new Node(40);
root.left.right = new Node(50);
root.right.left = new Node(60);
root.right.right = new Node(70);
root.left.right.left = new Node(80);
System.out.println(height(root));
}
}