Write a program that implements the BinarySearchTree interface given below . The type of data stored in this tree is Integer. You are free to use any type of implementation;
public interface BinarySearchTree {
public void insert(Integer data);
public int size();
public int height();
public boolean contains(Integer target);
}
class Node {
Node left, right, next;
Integer data;
Node () {
left = right = null;
data = 0;
}
}
public class BSTree extends Node implements BinarySearchTree {
static Node root;
static int countNode;
/**
* Creates a new instance of BSTree
*/
public BSTree() {
root = null;
}
public void insert(Integer data) {
if (root == null) {
root.data = data;
countNode++;
} else {
Node temp = new Node();
temp = root;
while (temp != null) {
if (temp.data < data) temp = temp.right;
else {
temp = temp.left;
}
temp.data = data;
countNode++;
}
}
}
public int size () {
return countNode;
}
public int height() {}
public boolean contains (Integer target) {}
public static void main(String[] args) {
BSTree bs = new BSTree();
bs.insert(12);
bs.insert(3);
bs.insert(14);
}
}
Can any one help me in writing contains and height method ?