Original Post
It has been a while since I have programmed in Java and I am having a hard time with the ways variables are passed. So as I understand it all variables passed into functions are passed into functions by reference, though the reference itself is passed by value. So how on earth would I do this: The problem exists below the comment I that reads "error". Basically I want the value pointed to by node to change to the object pointed to by z. But since the references are local to the function nothing changes. What design practices does one follow in Java to get something like this to work? -thanks
class BST{
private Node root;
/** Insert node x into the dictionary */
public void insert(Node z) {
insert(z, root);
}
private void insert(Node z, Node node){
if(node == null){
// error!!!!!
node = z;
return; // retun and unwind the stack
}
if(z.value < node.value)
insert(z, node.leftChild);
else
insert(z, node.rightChild);
}