Skip to content

Instantly share code, notes, and snippets.

@dineshbalaji
Created March 31, 2019 02:08
Show Gist options
  • Save dineshbalaji/d43c2aab7013c6439ef90e9e2c65648c to your computer and use it in GitHub Desktop.
Save dineshbalaji/d43c2aab7013c6439ef90e9e2c65648c to your computer and use it in GitHub Desktop.
function breathTraversal(tree) {
var queue = [tree];
var result = [];
while (queue.length > 0) {
var node = queue.shift();
result.push(node.value);
node.left && queue.push(node.left);
node.right && queue.push(node.right);
}
console.log('result of breath traversal :', result);
}
breathTraversal(tree);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment