From c4f7a45ed236fb1dd2d733b4a5d1863a2ff57145 Mon Sep 17 00:00:00 2001 From: 1700022814 <512620936@qq.com> Date: Sun, 18 Nov 2018 16:22:08 +0800 Subject: [PATCH] fix BinaryTree.java put method#644 --- DataStructures/Trees/BinaryTree.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/DataStructures/Trees/BinaryTree.java b/DataStructures/Trees/BinaryTree.java index a20d24ee..0c6e89cd 100644 --- a/DataStructures/Trees/BinaryTree.java +++ b/DataStructures/Trees/BinaryTree.java @@ -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;