<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
public class BST&lt;T extends Comparable&lt;T&gt;&gt; {
	private T value;

	/** All values in left are less than value. All values in right are greater than value. */
	private BST&lt;T&gt; left, right;

	public BST(T value) {
		this.value= value;
	}

	private int safeSize(BST&lt;T&gt; t) {
		return t == null ? 0 : t.size();
	}

	public int size() {
		return 1 + safeSize(left) + safeSize(right);
	}

	private boolean safeContains(BST&lt;T&gt; t, T v) {
		return t == null ? false : t.contains(v);
	}

	public boolean contains(T v) {
		int i= v.compareTo(value);
		if (i &lt; 0) {
			return safeContains(left, v);
		} else if (i &gt; 0) {
			return safeContains(right, v);
		} else /* i == 0 */ {
			return true;
		}
	}

	public void insert(T v) {
		int i= v.compareTo(value);
		if (i &lt; 0) {
			if (left == null) {
				left= new BST&lt;&gt;(v);
			} else {
				left.insert(v);
			}
		} else if (i &gt; 0) {
			if (right == null) {
				right= new BST&lt;&gt;(v);
			} else {
				right.insert(v);
			}
		} else /* i == 0 */ {
			return;
		}
	}

}
</pre></body></html>