dc-binary-tree
v0.1.0
Published
Binary Tree data structure for Javascript
Downloads
1
Readme
Usage
1. Building the tree:
var BinaryTree = require('binarytree');
var binaryTree = new BinaryTree('F');
let bNode = binaryTree.appendChildNode('B', 'left', alphabetTree.root);
let aNode = binaryTree.appendChildNode('A', 'left', bNode);
let dNode = binaryTree.appendChildNode('D', 'right', bNode);
let cNode = binaryTree.appendChildNode('C', 'left', dNode);
let eNode = binaryTree.appendChildNode('E', 'right', dNode);
let gNode = binaryTree.appendChildNode('G', 'right', binaryTree.root);
let iNode = binaryTree.appendChildNode('I', 'right', gNode);
let hNode = binaryTree.appendChildNode('H', 'left', iNode);
2. Transversing the tree:
// Breath Search First
let breathTransversal = binaryTree.BFS(); //['F','B','G','A','D','I','C','E','H'];
// Depth Search First
let preTransversal = binaryTree.DFS('preorder');//['F','B','A','D','C','E','G','I','H'];
let inorderTransversal = binaryTree.DFS('inorder'); //['A','B','C','D','E','F','G','H','I'];
let postorderTransversal = binaryTree.DFS('postorder');//['A','C','E','D','B','H','I','G','F'];