Binary Search Tree Recursive insert not displaying anything

后端 未结 3 1559
Happy的楠姐
Happy的楠姐 2021-01-21 10:36

I\'m doing a small Java work on Binary Search Tree but when I\'m implementing the recursive insert of a node into the tree and display it, I don\'t get anything. I\'ve been on i

3条回答
  •  生来不讨喜
    2021-01-21 11:07

    This sets the BST root and allow the class to work properly, change

        if ( root == null ) {
            root = new BSTNode( elem );
        }
    

    to

        if ( root == null ) {
            root = new BSTNode( elem );
            if ( root.element != null ) {
                this.root = root;
            }
        }
    

提交回复
热议问题