public void TestIterative()
        {
            var sol  = new BinaryTreeLevelOrderTraversal();
            var root = new TreeNode(3)
            {
                left  = new TreeNode(9),
                right = new TreeNode(20)
                {
                    left  = new TreeNode(15),
                    right = new TreeNode(7)
                }
            };
            var ret = sol.LevelOrder(root);
            IList <IList <int> > expected = new List <IList <int> >();

            expected.Add(new List <int>()
            {
                3
            });
            expected.Add(new List <int>()
            {
                9, 20
            });
            expected.Add(new List <int>()
            {
                15, 7
            });
            Utlilitiy.AssertAreEqual(expected, ret);
        }
예제 #2
0
        public void binaryTreeLevelOrderTraversalTest()
        {
            /*
             * [
             *   [3],
             *   [9,20],
             *   [15,7]
             * ]
             */
            var result = BinaryTreeLevelOrderTraversal.LevelOrder(root);

            Console.WriteLine("Level Order Traversal: ");
            for (int i = 0; i < result.Count; i++)
            {
                foreach (int node in result[i])
                {
                    Console.Write(node + ", ");
                }
                Console.WriteLine();
            }
        }