当前位置: 首页>>代码示例>>C#>>正文


C# BinaryTree.PrintIndentedPreOrder方法代码示例

本文整理汇总了C#中BinaryTree.PrintIndentedPreOrder方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryTree.PrintIndentedPreOrder方法的具体用法?C# BinaryTree.PrintIndentedPreOrder怎么用?C# BinaryTree.PrintIndentedPreOrder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryTree的用法示例。


在下文中一共展示了BinaryTree.PrintIndentedPreOrder方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BuildBinaryTree_PrintIndentedPreOrder_ShouldWorkCorrectly

    public void BuildBinaryTree_PrintIndentedPreOrder_ShouldWorkCorrectly()
    {
        // Arrange
        var binaryTree =
            new BinaryTree<string>("*",
                new BinaryTree<string>("-",
                    new BinaryTree<string>("+",
                        new BinaryTree<string>("3"),
                        new BinaryTree<string>("2")),
                    new BinaryTree<string>("*",
                        new BinaryTree<string>("9"),
                        new BinaryTree<string>("6"))),
                new BinaryTree<string>("8"));

        // Act
        var outputStream = new MemoryStream();
        using (var outputWriter = new StreamWriter(outputStream))
        {
            Console.SetOut(outputWriter);
            binaryTree.PrintIndentedPreOrder();
        }
        var output = Encoding.UTF8.GetString(outputStream.ToArray());

        // Assert
        var expectedOutput = "*\n  -\n    +\n      3\n      2\n    *\n      9\n      6\n  8\n";
        output = output.Replace("\r\n", "\n");
        Assert.AreEqual(expectedOutput, output);
    }
开发者ID:iliankostov,项目名称:DataStructures,代码行数:28,代码来源:UnitTestsBinaryTree.cs

示例2: Main

    static void Main()
    {
        var tree =
            new Tree<int>(7,
                new Tree<int>(19,
                    new Tree<int>(1),
                    new Tree<int>(12),
                    new Tree<int>(31)),
                new Tree<int>(21),
                new Tree<int>(14,
                    new Tree<int>(23),
                    new Tree<int>(6)));

        Console.WriteLine("Tree (indented):");
        tree.Print();

        Console.Write("Tree nodes:");
        tree.Each(c => Console.Write(" " + c));
        Console.WriteLine();
        
        Console.WriteLine();

        var binaryTree =
            new BinaryTree<string>("*",
                new BinaryTree<string>("+",
                    new BinaryTree<string>("3"),
                    new BinaryTree<string>("2")),
                new BinaryTree<string>("-",
                    new BinaryTree<string>("9"),
                    new BinaryTree<string>("6")));

        Console.WriteLine("Binary tree (indented, pre-order):");
        binaryTree.PrintIndentedPreOrder();

        Console.Write("Binary tree nodes (in-order):");
        binaryTree.EachInOrder(c => Console.Write(" " + c));
        Console.WriteLine();

        Console.Write("Binary tree nodes (post-order):");
        binaryTree.EachPostOrder(c => Console.Write(" " + c));
        Console.WriteLine();

        Console.ReadKey();

    }
开发者ID:Antoniy7,项目名称:cSharp,代码行数:45,代码来源:PlayWithTrees.cs


注:本文中的BinaryTree.PrintIndentedPreOrder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。