Changed find(int key) method to return null when node is not found, and updated docs accordingly. Issue #104.
This commit is contained in:
parent
0aee19d427
commit
e5381585a5
@ -67,18 +67,16 @@ class Tree{
|
|||||||
*/
|
*/
|
||||||
public Node find(int key) {
|
public Node find(int key) {
|
||||||
Node current = root;
|
Node current = root;
|
||||||
Node last = root;
|
|
||||||
while (current != null) {
|
while (current != null) {
|
||||||
last = current;
|
if(key < current.data) {
|
||||||
if(key < current.data)
|
|
||||||
current = current.left;
|
current = current.left;
|
||||||
else if(key > current.data)
|
} else if(key > current.data) {
|
||||||
current = current.right;
|
current = current.right;
|
||||||
//If you find the value return it
|
} else { // If you find the value return it
|
||||||
else
|
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
return last;
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user