Skip to content

JoseBarrios/dc-binary-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);

image

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'];

About

A Binary Tree data structure for Javascript

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published