var tree = {
"name" : "root",
"children" : [
{
"name" : "first child",
"children" : [
{
"name" : "first child of first",
"children" : []
},
{
"name" : "second child of first",
"children" : []
}
]
},
{
"name" : "second child",
"children" : []
}
]
}
function postOrder(root) {
if (root == null) return;
postOrder(root.children[0]);
postOrder(root.children[1]);
console.log(root.name);
}
postOrder(tree);
这是我使用 JSON 树在 javascript 中进行递归后序遍历的代码。
我将如何调整此代码以处理节点中的 N 个子节点?