// https://leetcode.com/discuss/interview-question/632709/Facebook-Interview-Question

        public void BinaryTreePreorderIteratorTest()
        {
            var root     = TreeNodeUtilities.GetTree("1,2,3,4,5,6,7,8,9,10");
            var iterator = new PreorderIterator(root);

            while (iterator.HasNext())
            {
                Console.Write($"{iterator.Next().val}, ");
            }
        }
예제 #2
0
        static void UsingIteratorOutOfAggregates()
        {
            Tree tree = new Tree();

            tree.InitData();

            BTIterator preorderIterator  = new PreorderIterator(tree);
            BTIterator inorderIterator   = new InorderIterator(tree);
            BTIterator postorderIterator = new PostorderIterator(tree);

            Print(preorderIterator);
            Print(inorderIterator);
            Print(postorderIterator);
        }