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 level order traversal, applying callback function iteratively to each node #18

Closed henrylin03 closed 3 months ago

henrylin03 commented 3 months ago

implements iterative solution for #10

tests

setup in index.mjs. the callback function we will use to test simply logs to console the data (value) of the node

import createTree from "./createTree.mjs";

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

const tree = createTree(testArray);

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

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

output: matches expected behaviour image