當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。