Skip to content
Snippets Groups Projects
Commit 26a9d8df authored by Adam Blank's avatar Adam Blank
Browse files

Merge branch 'patch-bst-find' into 'master'

Modify BST insert to correctly return old value



See merge request !4
parents 2534033d 7bd5250e
No related branches found
No related tags found
No related merge requests found
......@@ -58,9 +58,6 @@ public class BinarySearchTree<K extends Comparable<K>, V>
// We found the key!
if (direction == 0) {
if (value != null) {
current.value = value;
}
return current;
}
else {
......@@ -73,7 +70,7 @@ public class BinarySearchTree<K extends Comparable<K>, V>
// If value is null, we need to actually add in the new value
if (value != null) {
current = new BSTNode(key, value);
current = new BSTNode(key, null);
if (this.root == null) {
this.root = current;
}
......@@ -99,7 +96,10 @@ public class BinarySearchTree<K extends Comparable<K>, V>
@Override
public V insert(K key, V value) {
return find(key, value).value;
BSTNode current = find(key, value);
V oldValue = current.value;
current.value = value;
return oldValue;
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment