@@ -0,0 +1,1989 @@
+public class BST%3CT extends Comparable%3CT%3E%3E %7B%0A  static class TreeNode%3CT%3E %7B%0A    T value;%0A    TreeNode%3CT%3E left;%0A    TreeNode%3CT%3E right;%0A%0A    TreeNode(T value) %7B%0A      this.value = value;%0A      this.left = null;%0A      this.right = null;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A      return %22%5B%22 + value + %22, left: %22 + this.left + %22, right: %22 + this.right + %22%5D%22;%0A    %7D%0A  %7D%0A%0A  private TreeNode%3CT%3E root;%0A%0A  public BST() %7B%0A    this.root = null;%0A  %7D%0A%0A  private TreeNode%3CT%3E insert(TreeNode%3CT%3E node, T value) %7B%0A    if (node == null) return new TreeNode%3CT%3E(value);%0A    if (node.value.compareTo(value) %3C 0) %7B%0A      node.right = insert(node.right, value);%0A    %7D else if (node.value.compareTo(value) %3E 0) %7B%0A      node.left = insert(node.left, value);%0A    %7D%0A    return node;%0A  %7D%0A%0A  public void insert(T value) %7B%0A    this.root = insert(this.root, value);%0A  %7D%0A%0A  private boolean search(TreeNode%3CT%3E node, T value) %7B%0A    if (node == null) return false;%0A    if (node.value.compareTo(value) == 0) return true;%0A    if (node.value.compareTo(value) %3C 0) %7B%0A      return search(node.right, value);%0A    %7D else %7B%0A      return search(node.left, value);%0A    %7D%0A  %7D%0A%0A  public boolean search(T value) %7B%0A    return search(this.root, value);%0A  %7D%0A%0A  private TreeNode%3CT%3E remove(TreeNode%3CT%3E node, T value) %7B%0A    if (node == null) return node;%0A    if (node.value.compareTo(value) == 0) %7B%0A      if (node.left == null) return node.right;%0A      if (node.right == null) return node.left;%0A      TreeNode%3CT%3E tmp = node.left;%0A      while (tmp.right != null) %7B%0A        tmp = tmp.right;%0A      %7D%0A      tmp.right = node.right.left;%0A      node.right.left = node.left;%0A      return node.right;%0A    %7D else if (node.value.compareTo(value) %3C 0) %7B%0A      node.right = remove(node.right, value);%0A    %7D else %7B%0A      node.left = remove(node.left, value);%0A    %7D%0A    return node;%0A  %7D%0A%0A  public void remove(T value) %7B%0A    this.root = remove(this.root, value);%0A  %7D%0A%0A  @Override%0A  public String toString() %7B%0A    return %22BST: %22 + this.root;%0A  %7D%0A%7D%0A

add solutions