Skip to content

Commit c4f7a45

Browse files
fix BinaryTree.java put method#644
1 parent 819b7fd commit c4f7a45

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

DataStructures/Trees/BinaryTree.java

+4
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ public Node find(int key) {
6969
Node current = root;
7070
while (current != null) {
7171
if(key < current.data) {
72+
if(current.left == null)
73+
return current; //The key isn't exist, returns the parent
7274
current = current.left;
7375
} else if(key > current.data) {
76+
if(current.right == null)
77+
return current;
7478
current = current.right;
7579
} else { // If you find the value return it
7680
return current;

0 commit comments

Comments
 (0)