refactor: add/refactor method in include, simplified print code (#471)

This commit is contained in:
hpstory
2023-04-21 14:59:22 +08:00
committed by GitHub
parent 9c2e5e2831
commit 9eeefff447
24 changed files with 102 additions and 109 deletions

View File

@@ -37,11 +37,11 @@ public class binary_tree_bfs
{
/* 初始化二叉树 */
// 这里借助了一个从数组直接生成二叉树的函数
TreeNode? root = TreeNode.ArrToTree(new int?[] { 1, 2, 3, 4, 5, 6, 7 });
TreeNode? root = TreeNode.ListToTree(new List<int?> { 1, 2, 3, 4, 5, 6, 7 });
Console.WriteLine("\n初始化二叉树\n");
PrintUtil.PrintTree(root);
List<int> list = levelOrder(root);
Console.WriteLine("\n层序遍历的节点打印序列 = " + string.Join(",", list.ToArray()));
Console.WriteLine("\n层序遍历的节点打印序列 = " + string.Join(",", list));
}
}