Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

JavaScript binary tree

// find maixmum node in binary tree 
const Max = (root) => {
  let max = -Infinity;
  let stack = [root];

  while (stack.length) {
    let current = stack.pop();
    if (current.data > max) {
      max = current.data;
    }
    if (current.left !== null) stack.push(current.left);
    if (current.right !== null) stack.push(current.right);
  }

  return max;
};
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #JavaScript #binary #tree
ADD COMMENT
Topic
Name
5+6 =