@Override public void insert(int newValue) { // Empty tree if (this.parent == null && !hasValue) { this.value = newValue; this.hasValue = true; return; } if (this.value == newValue) return; int direction = newValue < value ? LEFT : RIGHT; BinarySearchTree child = children[direction]; if (child == null) { children[direction] = new BinarySearchTree(this, newValue); if (children[direction ^ 1] != null) ++height; } else { child.insert(newValue); } }