public static void Main(string[] args) { var root1 = new TreeNode(7) { left = new TreeNode(3), right = new TreeNode(15) { left = new TreeNode(9), right = new TreeNode(20), } }; var iterator1 = new BSTIterator(root1); Console.WriteLine(3 == iterator1.Next()); Console.WriteLine(7 == iterator1.Next()); Console.WriteLine(iterator1.HasNext()); Console.WriteLine(9 == iterator1.Next()); Console.WriteLine(iterator1.HasNext()); Console.WriteLine(15 == iterator1.Next()); Console.WriteLine(iterator1.HasNext()); Console.WriteLine(20 == iterator1.Next()); Console.WriteLine(false == iterator1.HasNext()); }
public void Test_Generic(string[] operations, string nodesArr, object[] expected) { var root = TreeNodeHelper.BuildTree(nodesArr); var sol = new BSTIterator(root); for (int i = 0; i < operations.Length; i++) { switch (operations[i]) { case "next": Assert.AreEqual(sol.Next(), expected[i]); break; case "hasNext": Assert.AreEqual(sol.HasNext(), expected[i]); break; } } }