Pushing before recursing left produces pre-order instead.
Acceptance criteria
- 1.#out should show 1-2-3.
Pushing before recursing left produces pre-order instead.
const tree = { v: 2, left: { v: 1, left: null, right: null }, right: { v: 3, left: null, right: null } }; const out = []; function walk(n) { if (!n) return; out.push(n.v); walk(n.left); walk(n.right); } walk(tree); document.querySelector('#out').textContent = out.join("-");
Output ready when you are
Press Run to render your code, or Submit to validate your solution.