Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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;

}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #tree #search
ADD COMMENT
Topic
Name
2+1 =