1class Student implements Comparable<Student>{
2int rollno;
3String name;
4int age;
5Student(int rollno,String name,int age){
6this.rollno=rollno;
7this.name=name;
8this.age=age;
9}
10
11public int compareTo(Student st){
12if(age==st.age)
13return 0;
14else if(age>st.age)
15return 1;
16else
17return -1;
18}
19}
1public class BinarySearchTree< T extends Comparable<T>> {
2 Node root;
3 class Node {
4 T data;
5 Node left;
6 Node right;
7
8 public Node(T data) {
9 this.data = data;
10 }
11 }
12
13 public boolean isEmpty() {
14 return root == null;
15 }
16
17 public void insert(T value) {
18 if(isEmpty())
19 root = new Node(value);
20 else
21 insert(root, value);
22 }
23
24 private void insert(Node node, T value) {
25
26 if(value.compareTo(node.data) < 0) {
27 if(node.left == null)
28 node.left = new Node(value);
29 else
30 insert(node.left, value);
31 }
32 else {
33 if(node.right == null)
34 node.right = new Node(value);
35 else
36 insert(node.right, value);
37 }
38 }
39
40}
41