You are viewing a single comment's thread. Return to all comments →
Javascript
function preOrder(root) { if (root === null) return; const results = []; const stack = [ root ]; while (stack.length > 0) { const current = stack.pop(); results.push(current.data) // console.log(current.data) if (current.right) stack.push(current.right); if (current.left) stack.push(current.left) } console.log(results.join(' ')) }
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Preorder Traversal
You are viewing a single comment's thread. Return to all comments →
Javascript