add JavaScript codes for PrintUtil

This commit is contained in:
IsChristina
2022-12-04 23:14:09 +08:00
parent db416cf4bb
commit 003dcc56f4
5 changed files with 105 additions and 13 deletions

View File

@@ -4,7 +4,8 @@
* Author: IsChristina (christinaxia77@foxmail.com)
*/
let { arrToTree } = require("../include/TreeNode");
const { arrToTree } = require("../include/TreeNode");
const { printTree } = require("../include/PrintUtil");
/* 层序遍历 */
function hierOrder(root) {
@@ -29,7 +30,7 @@ function hierOrder(root) {
// 这里借助了一个从数组直接生成二叉树的函数
var root = arrToTree([1, 2, 3, 4, 5, 6, 7, null, null, null, null, null, null, null, null ]);
console.log("\n初始化二叉树\n");
console.log(root);
printTree(root);
/* 层序遍历 */
let list = hierOrder(root);