I am trying to insert a node into my tree using Node as a nested class. I can't figure out why the tree.root
won't save the node using my method insertNode
public class Tree {
Node root;
private class Node {
int value;
Node(int value) {
this.value = value;
}
}
public static void main(String[] args) {
Tree tree = new Tree();
tree.insertNode(4, tree.root);
System.out.println(tree.root);
}
public void insertNode(int value, Node n){
if(n == null ){
n = new Node(value);
}
}
}
>> null
What am I missing? Thank you for your help