henrylin03 / odin-binary-search-tree

Implementing balanced binary search tree (BST) from a sorted array in JavaScript, as part of The Odin Project's "Full Stack JavaScript" course
MIT License
0 stars 0 forks source link

implement inorder (depth first) traversal of tree (left -> root -> right), applying callback function to each node #23

Closed henrylin03 closed 3 months ago

henrylin03 commented 3 months ago

fixes #11

results are sorted

tests

setup:

//index.mjs
import createTree from "./createTree.mjs";

const testArray = [1, 2, 7, 4, 23, 8, 9, 10, 4, 3, 5, 7, 9, 67, 6345, 324];
const printData = (node) => console.log(node.data);

const tree = createTree(testArray);

tree.buildTree();
tree.prettyPrint();

// test inOrder traversal
tree.inOrder(printData);

output: image