本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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();
}
示例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();
}