mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 21:24:53 +08:00
Optimize arrToTree function
in java, cpp, py, go, js, ts.
This commit is contained in:
@ -28,10 +28,10 @@ function hierOrder(root) {
|
||||
/* Driver Code */
|
||||
/* 初始化二叉树 */
|
||||
// 这里借助了一个从数组直接生成二叉树的函数
|
||||
var root = arrToTree([1, 2, 3, 4, 5, 6, 7, null, null, null, null, null, null, null, null]);
|
||||
var root = arrToTree([1, 2, 3, 4, 5, 6, 7]);
|
||||
console.log("\n初始化二叉树\n");
|
||||
printTree(root);
|
||||
|
||||
/* 层序遍历 */
|
||||
let list = hierOrder(root);
|
||||
console.log("\n层序遍历的结点打印序列 = " + list);
|
||||
console.log("\n层序遍历的结点打印序列 = " + list);
|
||||
|
||||
@ -40,7 +40,7 @@ function postOrder(root) {
|
||||
/* Driver Code */
|
||||
/* 初始化二叉树 */
|
||||
// 这里借助了一个从数组直接生成二叉树的函数
|
||||
var root = arrToTree([1, 2, 3, 4, 5, 6, 7, null, null, null, null, null, null, null, null]);
|
||||
var root = arrToTree([1, 2, 3, 4, 5, 6, 7]);
|
||||
console.log("\n初始化二叉树\n");
|
||||
printTree(root);
|
||||
|
||||
@ -58,4 +58,3 @@ console.log("\n中序遍历的结点打印序列 = " + list);
|
||||
list.length = 0;
|
||||
postOrder(root);
|
||||
console.log("\n后序遍历的结点打印序列 = " + list);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user