|
|
|
@ -31,8 +31,10 @@ public class BST { |
|
|
|
// search tree, keeping the tree ordered. |
|
|
|
public void add(String value) { |
|
|
|
BSTNode to_add = new BSTNode(value); |
|
|
|
if (m_root == null) |
|
|
|
if (m_root == null) { |
|
|
|
m_root = to_add; |
|
|
|
m_size++; |
|
|
|
} |
|
|
|
else { |
|
|
|
BSTNode current = m_root; |
|
|
|
BSTNode parent = null; |
|
|
|
@ -45,7 +47,7 @@ public class BST { |
|
|
|
} |
|
|
|
else if (comparison < 0) { |
|
|
|
parent = current; |
|
|
|
current = current.getRight(); |
|
|
|
current = current.getLeft(); |
|
|
|
} |
|
|
|
else |
|
|
|
return; |
|
|
|
@ -54,6 +56,7 @@ public class BST { |
|
|
|
parent.setRight(to_add); |
|
|
|
else |
|
|
|
parent.setLeft(to_add); |
|
|
|
m_size++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|