I\'m currently learning about trees using java and i have some errors going on here in the insertion of items in a binary tree I don\'t why it doesn\'t work
this is the
Fine code, but recursing does not step further
item.left = insertNode(item.left, d);
item.right = insertNode(item.right, d);
And the initial root is not updated:
root = insertNode(root, d);
The else part or final return is superfluous.
Something on the code style
insertNode
has a node as input, and returns the updated node value, hence the call "pattern" should look like
X = insertNode(X, d); // X is some expression
This is because java can never assign to the passed argument expression: it has no pass-by-reference, but pass-by-value; f(x)
never assigns to x
.