private static BinaryTreeNode Rectify(BinaryTreeNode binaryTreeNode, int value1, int value2) { if (binaryTreeNode == null) { return(null); } BinaryTreeNode leftNode = Rectify(binaryTreeNode.GetLeftNode(), value1, value2); if (previousNode != null && previousNode.GetData() > binaryTreeNode.GetData() && previousNode.GetData() == value1 && value2 < value1) { binaryTreeNode.SetLeftNode(leftNode); binaryTreeNode.SetData(value1); previousNode.SetData(value2); return(binaryTreeNode); } previousNode = binaryTreeNode; BinaryTreeNode right = Rectify(binaryTreeNode.GetRightNode(), value1, value2); binaryTreeNode.SetLeftNode(leftNode); binaryTreeNode.SetRightNode(right); return(binaryTreeNode); }
private static BinaryTreeNode _ConstructedTree(int start, int end) { if (start < end) { return(null); } int mid = (end - start) / 2; BinaryTreeNode left = _ConstructedTree(start, mid - 1); BinaryTreeNode root = new BinaryTreeNode(); root.SetData(BSTNodesArray[mid]); BinaryTreeNode right = _ConstructedTree(mid + 1, end); root.SetLeftNode(left); root.SetRightNode(right); return(root); }