24 lines
501 B
Java
24 lines
501 B
Java
|
public class SearchTree<T> {
|
||
|
|
||
|
private TreeNode<T> root;
|
||
|
private TreeComparator<T> comparator;
|
||
|
|
||
|
public SearchTree(TreeComparator<T> comparator) {
|
||
|
this.comparator = comparator;
|
||
|
}
|
||
|
|
||
|
public void add(T object) {
|
||
|
if (root != null) root.add(object);
|
||
|
else root = new TreeNode<T>(this, object);
|
||
|
}
|
||
|
|
||
|
public TreeComparator<T> getComparator() {
|
||
|
return comparator;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String toString() {
|
||
|
return root.toString();
|
||
|
}
|
||
|
}
|