binary search tree search javascript code example
Example 1: search node in tree javascript
var stack = [], node, ii;
stack.push(root);
while (stack.length > 0) {
node = stack.pop();
if (node.title == 'randomNode_1') {
return node;
} else if (node.children && node.children.length) {
for (ii = 0; ii < node.children.length; ii += 1) {
stack.push(node.children[ii]);
}
}
}
return null;
Example 2: binary tree javascript
Toast.makeText(getActivity(), "This is my Toast message!",
Toast.LENGTH_LONG).show();