I have this code fragment
class bst {
public node root=null;
bst() {
root=null;
}
public void insert(int data) {
insert(this.root,data);
}
private void insert(node ro,int data) {
if (ro==null) {
print ("root is null");
ro=new node(data);
} else if (data>ro.data)
insert(ro.right,data);
else
insert(ro.left,data);
}
private void print (String str)
{
System.out.println(str);
}
}
When I call the insert
function like insert(5); insert(8);
it alwaty prints root is null
.
whats the problem??