Merge pull request #648 from themanchangechina/master

fix BinaryTree.java put method
This commit is contained in:
Libin Yang 2018-12-03 10:07:12 +08:00 committed by GitHub
commit 217b85f04a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,8 +69,12 @@ class Tree{
Node current = root;
while (current != null) {
if(key < current.data) {
if(current.left == null)
return current; //The key isn't exist, returns the parent
current = current.left;
} else if(key > current.data) {
if(current.right == null)
return current;
current = current.right;
} else { // If you find the value return it
return current;