mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 17:56:02 +08:00
Merge pull request #113 from mpokryva/node-find-fix
BinaryTree find(int key) fix
This commit is contained in:
@ -67,18 +67,16 @@ class Tree{
|
||||
*/
|
||||
public Node find(int key) {
|
||||
Node current = root;
|
||||
Node last = root;
|
||||
while (current != null) {
|
||||
last = current;
|
||||
if(key < current.data)
|
||||
if(key < current.data) {
|
||||
current = current.left;
|
||||
else if(key > current.data)
|
||||
} else if(key > current.data) {
|
||||
current = current.right;
|
||||
//If you find the value return it
|
||||
else
|
||||
} else { // If you find the value return it
|
||||
return current;
|
||||
}
|
||||
return last;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user