Skip to content

Instantly share code, notes, and snippets.

@yschen25
Created April 7, 2022 16:10
Show Gist options
  • Save yschen25/4eb5e87b1b8f85ca84a44f606ebaa9f1 to your computer and use it in GitHub Desktop.
Save yschen25/4eb5e87b1b8f85ca84a44f606ebaa9f1 to your computer and use it in GitHub Desktop.
const postorder = function (node, acc = []) {
if (!node) return acc;
const { value, left, right } = node;
postorder(left, acc);
postorder(right, acc);
acc.push(value);
return acc;
};
console.log(postorder(tree)); // [6, 7, 3, 4, 1, 8, 9, 5, 2, 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment