1.0.11 • Published 6 years ago
@coutcout/tree-datastructure v1.0.11
tree-datastructure
This package allow creating simple tree datastructures.
Installation
npm install @coutcout/tree-datastructure
Use
Create a tree
let tree = new Tree("This is the root");
Get the root
let root = tree.getRoot();
Add a node to the tree
let node1 = root.addChild("I'm the first childNode");
let node11 = node1.addChild("Hi");
let node2 = root.addChild("I'm the second child");
let node3 = new TreeNode("Bye bye");
root.addChildTreeNode(node3);
Result
digraph G {
root -> node1
root -> node2
root -> node3
node1 -> node11
}
Get a parent
let parent1 = node11.getParent(1);
// parent = root
let parent2 = node11.getParent();
// parent = node1
Get childs
let childs = root.getChilds();
// childs = [node1, node2, node3]