static void Main(string[] args)
        {
            TreeNode root = new TreeNode(5);

            root.left        = new TreeNode(3);
            root.right       = new TreeNode(6);
            root.left.left   = new TreeNode(2);
            root.left.right  = new TreeNode(4);
            root.right.right = new TreeNode(7);
            var obj = new BSTIterator(root);

            Console.WriteLine("BST Iterator {0}", obj.HasNext());
            Console.WriteLine("BST Iterator {0}", obj.Next());
        }
Beispiel #2
0
        private static bool UnitTest5()
        {
            var node2 = new TreeNode(2);
            var node3 = new TreeNode(3);
            var node1 = new TreeNode(1);

            node3.left  = node1;
            node1.right = node2;

            var iterator = new BSTIterator(node3);

            if (!iterator.HasNext())
            {
                Console.WriteLine("Failed has next in UT 5");
                return(false);
            }
            if (iterator.Next() != 1)
            {
                Console.WriteLine("Failed to get next in UT 5");
                return(false);
            }
            if (!iterator.HasNext())
            {
                Console.WriteLine("Failed has next after extraction in UT 5");
                return(false);
            }
            if (iterator.Next() != 2)
            {
                Console.WriteLine("Failed to get next in UT 5");
                return(false);
            }
            if (!iterator.HasNext())
            {
                Console.WriteLine("Failed has next after extraction in UT 5");
                return(false);
            }
            if (iterator.Next() != 3)
            {
                Console.WriteLine("Failed to get next in UT 5");
                return(false);
            }
            if (iterator.HasNext())
            {
                Console.WriteLine("Failed has next after extraction in UT 5");
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        private static bool UnitTest1()
        {
            var iterator = new BSTIterator(new TreeNode(1));

            if (!iterator.HasNext())
            {
                Console.WriteLine("Failed has next in UT 1");
                return(false);
            }
            if (iterator.Next() != 1)
            {
                Console.WriteLine("Failed to get next in UT 1");
                return(false);
            }
            if (iterator.HasNext())
            {
                Console.WriteLine("Failed has next after extraction in UT 1");
                return(false);
            }

            return(true);
        }