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


C# Tree.Print方法代码示例

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


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

示例1: Main

        static void Main()
        {
            Tree<int> corner = new Tree<int>(0);
            int nodeCnts = int.Parse(Console.ReadLine());
            for (int i = 0; i < nodeCnts - 1; i++)
            {
                string[] edge = Console.ReadLine().Split(' ');
                int parentValue = int.Parse(edge[0]);
                Tree<int> parentNode = Tree<int>.GetTreeNodeByValue(parentValue);
                int childValue = int.Parse(edge[1]);
                Tree<int> childNode = Tree<int>.GetTreeNodeByValue(childValue);
                parentNode.Children.Add(childNode);
                childNode.Parent = parentNode;
                if (i == 0)
                {
                    corner = parentNode;
                }
            }

            int pathSum = int.Parse(Console.ReadLine());
            int subTreeSum = int.Parse(Console.ReadLine());

            Console.WriteLine();
            corner.Print();
        }
开发者ID:flyer87,项目名称:Data_structures,代码行数:25,代码来源:Program.cs

示例2: BuildTree_PrintTree_ShouldWorkCorrectly

    public void BuildTree_PrintTree_ShouldWorkCorrectly()
    {
        // Arrange
        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)));

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

        // Assert
        var expectedOutput = "7\n  19\n    1\n    12\n    31\n  21\n  14\n    23\n    6\n";
        output = output.Replace("\r\n", "\n");
        Assert.AreEqual(expectedOutput, output);
    }
开发者ID:stansem,项目名称:SoftUni,代码行数:28,代码来源:Test.cs

示例3: Main

        static void Main()
        {
            Tree<int> tree =
                new Tree<int>(7,
                    new Tree<int>(12),
                    new Tree<int>(2,
                        new Tree<int>(18)
                    ),
                    new Tree<int>(55),
                    new Tree<int>(3),
                    new Tree<int>(276,
                        new Tree<int>(10),
                        new Tree<int>(78,
                            new Tree<int>(1078),
                            new Tree<int>(11)
                        ),
                new Tree<int>(2)
                )
            );

            Console.WriteLine("Tree<int> tree = ");
            tree.Print();

            Console.WriteLine("Depth-First Search (DFS) ->");
            DepthFirstSearch(tree);
        }
开发者ID:magdalena70,项目名称:CSharp-DataStructures,代码行数:26,代码来源:Trees_Implementations.cs

示例4: Main

 static void Main(string[] args)
 {
     Tree<int> tree = new Tree<int>();
     tree.Create(new int[5] {32,12,83,2,43 });
     tree.Print();
     Console.WriteLine();
     tree.PringDec();
     Console.ReadLine();
 }
开发者ID:kiler4747,项目名称:Curses,代码行数:9,代码来源:Program.cs

示例5: 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


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