private static BinarySearchTreeNode construct(int[] numArr, int start, int end) { if (start > end) return null; int middle = (start + end) / 2; BinarySearchTreeNode node = new BinarySearchTreeNode(numArr[middle]); node.setLeftNode(construct(numArr, start, middle - 1)); node.setRightNode(construct(numArr, middle + 1, end)); return node; }
private static BinarySearchTreeNode trimTree(BinarySearchTreeNode node, int small, int large) { if (node == null) return null; node.setLeftNode(trimTree(node.getLeftNode(), small, large)); node.setRightNode(trimTree(node.getRightNode(), small, large)); if (node.getData() < small) return node.getRightNode(); else if (node.getData() > large) return node.getLeftNode(); else return node; }