Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

search node in tree javascript

var stack = [], node, ii;
stack.push(root);

while (stack.length > 0) {
    node = stack.pop();
    if (node.title == 'randomNode_1') {
        // Found it!
        return node;
    } else if (node.children && node.children.length) {
        for (ii = 0; ii < node.children.length; ii += 1) {
            stack.push(node.children[ii]);
        }
    }
}

// Didn't find it. Return null.
return null;
Comment

javascript tree search


const isPresent = (target , root)=>{
  if (root === null) return null;
  const result = [];
  const queue = [root];


  while (queue.length > 0) {
    const current = queue.shift();
    if(target===current.data){
      return true
    }
    result.push(current.data);
    if (current.left) queue.push(current.left);
    if (current.right) queue.push(current.right);
  }
  return false;

}
Comment

PREVIOUS NEXT
Code Example
Javascript :: responsive navbar react 
Javascript :: code for random password generator in javascript 
Javascript :: jsdoc default value 
Javascript :: ng-options angularjs 
Javascript :: axios response error interceptor 
Javascript :: arguments object 
Javascript :: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 
Javascript :: var vs let javascript 
Javascript :: javascript promise example 
Javascript :: js return 
Javascript :: comment field react 
Javascript :: js array map concat 
Javascript :: Remove uploaded file in jquery 
Javascript :: javascript return multiple values 
Javascript :: JavaScript (SMonkey 60.2.3) sample 
Javascript :: suitescript dialog box 
Javascript :: javascript if object element exists 
Javascript :: js spin wheel color 
Javascript :: javascript Adding Properties And Methods in an Object 
Javascript :: zigale assefa 
Javascript :: javascript variable name arguments and eval are not allowed 
Javascript :: actionscript round roundnumber 
Javascript :: jquery v3.3.1 download 
Javascript :: mongoose schema index of multiple columns 
Javascript :: Json to npy file 
Javascript :: phaser animation from json 
Javascript :: Is he gonna survive 
Javascript :: Move capital letters to the beginning 
Javascript :: marko js 
Javascript :: reduce function javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =