I have some code. In main function i push six element in BST. when i look to debugger, i see that variable size = 5, but variable root = null. Why variable root not change.
package Search;
public class BST<Key extends Comparable<Key>, Val> {
private class Node{
Key key;
Val val;
Node left;
Node right;
Node prev;
Node(Key k, Val v){
key = k;
val = v;
}
}
public void push(Key k, Val v){
push(root,k,v);
}
private void push(Node x, Key k, Val v){
if(x == null){
x = new Node(k,v);
size++;
return;
}
int cmp = x.key.compareTo(k);
if(cmp > 0)
push(x.left,k,v);
else if(cmp < 0)
push(x.right,k,v);
else
x.val = v;
}
Node root = null;
int size = 0;
public static void main(String args[]){
BST<String,Integer> bst = new BST<String, Integer>();
bst.push("c",1);
bst.push("b",2);
bst.push("d",3);
bst.push("a",4);
bst.push("e",5);
bst.push("c",6);
}
}