JavaScript Depth-first search

被刻印的时光 ゝ 提交于 2019-11-30 09:54:49

The problem is your addChild() method only expects one parameter, but you are passing in multiple nodes to it.

Change your calling code to:

node1.addChild(node2);
node1.addChild(node7);
node1.addChild(node8);

node2.addChild(node3);
node2.addChild(node6);

node3.addChild(node4);
node3.addChild(node5);

node8.addChild(node9);
node8.addChild(node12);

node9.addChild(node10);
node9.addChild(node11);

Or you can change addChild to accept multiple children (probably want to change the name too):

this.addChildren = function () {
    for (var i = 0; i < arguments.length; i++) {
        children.push(arguments[i]);
    }
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!