要掌握使用二叉搜索树的方法,最好从 contains() 方法
开始。contains() 方法接受一个值作为参数,如果值存在于
树中则返回 true,否则返回 false。此方法遵循基本的二叉
搜索算法来确定该值是否存在:
BinarySearchTree.prototype = {
//more code
contains: func$on(value){
var found = false,
current = this._root
//make sure there's a node to search
while(!found && current){
//if the value is less than the current node's, go le
if (value < current.value){
current = current.le;
//if the value is greater than the current node's, go
评论0
最新资源