interface BinarySearchTree {
public void insert(Integer data);
public int size();
public int height();
public boolean contains(Integer target);
}

and I have to implement BST with all these functions. I have implemented the first insert and size like this way -

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 by writing the code of finding the height and contains function ?

stephen84s commented: Forum flooding, I strongly recommend you first reading the rules I had linked to before going on flooding spree -1
masijade commented: Stop this already. Very anoying and is only going to cause people to ignore you, not help you (although it's a hand-out, and not help, that you want). -2

Recommended Answers

All 3 Replies

Please post your code in

tags, its almost impossible to read without them.

Please post your code in tags, its almost impossible to read without them.

Already had given her this advice in the first clone of this thread, but she just rather chose to just ignore it and created this one

Already had given her this advice in the first clone of this thread, but she just rather chose to just ignore it and created this one

Oh wow. I don't see very much mod activity on this forum...maybe some more mods, or just more intense actions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.