示例#1
0
文件: Program.cs 项目: octavioccl/DSA
        private static void BinaryTreeWalks()
        {
            BinaryTree<int> t = new BinaryTree<int>(1)
            {
                LeftChild = new BinaryTree<int>(2),
                RightChild = new BinaryTree<int>(3)
            };
            t.LeftChild.LeftChild = new BinaryTree<int>(4);
            t.LeftChild.RightChild = new BinaryTree<int>(5);

            t.RightChild.LeftChild = new BinaryTree<int>(6);
            t.RightChild.RightChild = new BinaryTree<int>(7);

            foreach (var nodeValue in t.PreorderTreeWalk())
            {
                Console.WriteLine(nodeValue);
            }

            foreach (var nodeValue in t.PostorderTreeWalk())
            {
                Console.WriteLine(nodeValue);
            }

            foreach (var nodeValue in t.InorderTreeWalk())
            {
                Console.WriteLine(nodeValue);
            }
        }