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;
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;
}