コード例 #1
0
        void Main(string[] args)
        {
            //       1
            //      / \
            //     2   3

            // in-order: 213

            var root = new Node <int>(1,
                                      new Node <int>(2), new Node <int>(3));

            var it = new InOrderIterator <int>(root);

            while (it.MoveNext())
            {
                Console.Write(it.Current.Value);
                Console.Write(",");
            }
            Console.WriteLine();

            var tree = new BinaryTree <int>(root);

            //Console.WriteLine(string.Join(",", tree.InOrder.Select(x => x.Value)));
            foreach (var node in tree)
            {
                Console.WriteLine(node.Value);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //   1
            //  / \
            // 2   3

            // in-order:  213
            // preorder:  123
            // postorder: 231

            var root = new Node <int>(1,
                                      new Node <int>(2), new Node <int>(3));

            // C++ style
            var it = new InOrderIterator <int>(root);

            while (it.MoveNext())
            {
                Console.Write(it.Current.Value);
                Console.Write(',');
            }
            Console.WriteLine();

            // C# style
            var tree = new BinaryTree <int>(root);

            Console.WriteLine(string.Join(",", tree.NaturalInOrder.Select(x => x.Value)));

            // duck typing!
            foreach (var node in tree)
            {
                Console.WriteLine(node.Value);
            }

            Console.ReadLine();
        }