为了账号安全,请及时绑定邮箱和手机立即绑定

想问下Cannot read property 'key' of undefined

function BinaryTree(key) {

var Node = function(key) {

this.key = key;

this.left = null;

this.righr = null;

};


var root = null;


var insertNode = function(node,newNode) {


if (newNode.key < node.key) { 

if (node.left === null) {

node.left = newNode; 

} else {

insertNode(node.left,newNode); 

}

} else{

if (node.right ===null) {

node.right = newNode;

} else {

insertNode(node.right,newNode);

}

}

}

this.insert = function(key) {

var newNode = new Node(key);

if (root === null) {

root = newNode;

} else {

insertNode(root,newNode); 

}

};

}


var nodes = [8,3,10,1,6,14,4,7,13];

var binaryTree = new BinaryTree(); 

        nodes.forEach(function(key) {

            binaryTree.insert(key);

        });


正在回答

1 回答

找到问题了,right打错了...

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

想问下Cannot read property 'key' of undefined

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信