public void Test3(int k, int expectedResult) { int[] array = { 45, 30, 46, 10, 36, -1, 49, 8, 24, 34, 42, 48, -1, 4, 9, 14, 25, 31, 35, 41, 43, 47, -1, 0, 6, -1, -1, 11, 20, -1, 28, -1, 33, -1, -1, 37, -1, -1, 44, -1, -1, -1, 1, 5, 7, -1, 12, 19, 21, 26, 29, 32, -1, -1, 38, -1, -1, -1, 3, -1, -1, -1, -1, -1, 13, 18, -1, -1, 22, -1, 27, -1, -1, -1, -1, -1, 39, 2, -1, -1, -1, 15, -1, -1, 23, -1, -1, -1, 40, -1, -1, -1, 16, -1, -1, -1, -1, -1, 17 }; BSTTreeNode root = BinarySearchTreeGenerator.GenerateFromArray(array); KthSmallestElementSolution solution = new KthSmallestElementSolution(); int result = solution.Solve(root, k); result.Should().Be(expectedResult); }
public void Test1(int k, int expectedResult) { BSTTreeNode root = new BSTTreeNode(3); BSTTreeNode rootLeft = new BSTTreeNode(1); root.left = rootLeft; BSTTreeNode rootRight = new BSTTreeNode(4); root.right = rootRight; BSTTreeNode rootLeftRight = new BSTTreeNode(2); rootLeft.right = rootLeftRight; KthSmallestElementSolution solution = new KthSmallestElementSolution(); int result = solution.Solve(root, k); result.Should().Be(expectedResult); }