New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What should be returned by the remove method of the BinarySearchTreeNode? #57
Comments
It should be relevant, it is setting a delimiter whether to continue, fall back or if Sorry, if I am not clear enough. |
Thanks for the explanation, @intern0t . For clarity, please specify these things: Should these properties of the returned object correspond to the tree state before the node is deleted or after? For example, is it correct to change the javascript-algorithms/src/data-structures/tree/binary-search-tree/BinarySearchTreeNode.js Line 111 in 9de6bc7
Same question to the javascript-algorithms/src/data-structures/tree/binary-search-tree/BinarySearchTreeNode.js Line 106 in 9de6bc7
javascript-algorithms/src/data-structures/tree/binary-search-tree/BinarySearchTreeNode.js Line 110 in 9de6bc7
Also, if you add this check to the BinarySearchTreeNode.test.js, it will fail: it('should return removed node containing a value that should have been deleted', () => {
const bstRootNode = new BinarySearchTreeNode();
bstRootNode.insert(10);
bstRootNode.insert(20);
bstRootNode.insert(30);
bstRootNode.insert(15);
const removedNode1 = bstRootNode.remove(20);
expect(removedNode1.value).toBe(20);
}); |
I think that properties of the returned object correspond to the tree state before the node is deleted.
You have changed the value of |
Yes, you right @m-maksyutin, there is an uncertainty in removal method. To avoid similar confusion I've changed the code so that removal method will return boolean (whether node has been successfully deleted or not). Because returning the node truly brings confusion about its value, left, right and parent properties. |
Hi! The
remove
method returns a BinarySearchTreeNode object. But there is one uncertain moment. What should be contained in the properties of this object, such as theparent
,left
,right
? Are these properties relevant? Or they must be null?The text was updated successfully, but these errors were encountered: