Once again, java pass by reference by value kills me. This code :
public Position<T> insert(T obj) {
return _insert(_root,obj);
}
calls this private helper :
/* Helper functions */
private Position<T> _insert(BTreeNode<T> root, T insertValue)
{
if(root == null){
root = new BTreeNode<T>(insertValue);
}
else
{
int result = insertValue.compareTo(root.element());
if(result < 0){ //value < root
_insert(root.getLeft(),insertValue);
}
else if(result > 0){ // value > root
_insert(root.getRight(),insertValue);
}
}
return root; //either a new leaf or the position with the same data
}
It does not work because I can't change the reference of the root. Any one wanna
just throw some ideas around?