ihave built all the functions for the binary tree
i added a members
i built a search method
and it says that there is no such object
i cant understand why???
[code]
public class main {
/**
* @param args
*/
public static void main(
String[] args) {
// TODO Auto-generated method stub
btree t=new btree();
int x=7;
t.insert(x);
t.insert(x);
t.insert(x);
System.out.println(t.find(x));
}
}
public class bnode {
private bnode left;
private bnode right;
private Object data;
bnode(Object data)
{
this.data=data;
left=null;
right=null;
}
public void insert(Object x)
{
double i;
i=Math.random();
if (i>=0.5)
{
if (right==null){
this.right=new bnode(x);
}
else
{
right.insert(x);
}
}
if (i<0.5){
if (left==null){
this.left=new bnode(x);
}
else
{
left.insert(x);
}
}
}
public boolean find(Object x){
if (this.data.equals(x)) {
return true;
}
else
{
if (right!=null){
right.find(x);
}
if (left!=null){
left.find(x);
}
}
return false;
}
}
public class btree {
bnode root;
btree()
{
root=null;
}
public void insert(Object x)
{
if (root==null){
root=new bnode(x);
}
else
{
root.insert(x);
}
}
public boolean find(Object x)
{
if (root.equals(x)){
return true;
}
else
{
root.find(x);
}
return false;
}
}
[/code