标签:blog io ar java strong sp 数据 div on
树:以分层的方式存储数据;节点:根节点,子节点,父节点,叶子节点(没有任何子节点的节点);层:根节点开始0层;
二叉树:每个节点子节点不超过两个;查找快(比链表),添加,删除快(比数组);
BST:二叉树查找:
实现的基本代码:
function Node (data,left,right) {
this.data = data;
this.show = sh
}
function show() {
console.log(this.data);
}
function BST() {
this.root = root;
this.insert = insert;
}
function insert(data) {
var n = new Node(data,null,null);
if(this.root === null) {
this.root = n;
} else {
var currNode = this.root,parent;
while(true) {
parent = currNode;
if(data < currNode.data) {
currNode = currNode.left;
if(currNode === null) {
parent.left = n;
break;
}
} else {
currNode = currNode.right;
if(currNode === null) {
parent.right = n;
break;
}
}
}
}
}
标签:blog io ar java strong sp 数据 div on
原文地址:http://www.cnblogs.com/jinkspeng/p/4032769.html