0

Java Binary Trees

Why isn't it working? ---------------------------------------------------------- //adds a new Node to the tree (in a way of a Binary Search tree): public void add(int data){ insert(this.root, data); } private void insert(Node node, int data){ if (node == null){ //stops the recursion, some node will have to be null sometime.. //also sets the actual real root of the tree a value... : node = new Node(data); }else if(node.getData() > data){ //left side of tree: insert(node.getLeft(), data); }else if(node.getData() < data){ //right side of tree: insert(node.getRight(), data); } }

17th Jun 2021, 6:25 PM
Yahel
Yahel - avatar
1 Odpowiedź
0
node == null node = new object but node and object inside are lost in the end of method
20th Jun 2021, 8:46 PM
zemiak