javascript 分钟 - 值在-BST

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 分钟 - 值在-BST相关的知识,希望对你有一定的参考价值。

// Find a minimal value in binary tree

let node = function(data) {
  this.data = data;
  this.left = null;
  this.right = null;
}

let findMin = function(root) {
  let curr = root;
  while(curr.left) {
    curr = curr.left;
  }
  console.log('Min: ', curr.data);
}

// building following tree
//        5
//       / \
//      3   6
//     / \   \
//    1   4   8
//   / \     / \
//  0   2   7   9
let root = new node(5);
root.left = new node(3);
root.right = new node(6);
root.left.left = new node(1);
root.left.right = new node(4);
root.right.right = new node(8);
root.left.left.left = new node(0);
root.left.left.right = new node(2);
root.right.right.left = new node(7);
root.right.right.right = new node(9);

findMin(root);

以上是关于javascript 分钟 - 值在-BST的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript之BST

javascript 遍历有序BST

javascript 遍历预购BST

javascript BST-从阵列

javascript实现BST

无法在JavaScript中将String BST日期格式转换为UTC