慕勒4048106
2019-04-16 16:48
<html>
<body>
</body>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
function BinaryTree(){
var Node = function(key) {
this.key = key;
this.left = null;
this.right = 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{
console.log("big");
if(node.rigth == 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);
});
</script>
</html>
=== 是类型都要对等 ,==可以帮你做转化的,不一样
Javascript实现二叉树算法
46934 学习 · 97 问题
相似问题