首页 > 代码库 > javascript 搜索二叉树

javascript 搜索二叉树

   function Tree() {
     this.root = null;
   }
   Tree.prototype = {
     constructor: Tree,
     addItem: function(value) {
       var Node = {
         data: value,
         left: null,
         right: null
       };
       if (this.root == null) {
         this.root = Node;
       } else {
         var current = this.root;
         var parent = current;
         while (current !== null) {
           parent = current;
           if (value < current.data) {
             current = current.left;
             continue; //此处容易忽略,缺少下一句if判断current.data会报错
           }
           if (value =http://www.mamicode.com/== current.data) {>

javascript 搜索二叉树