-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrees.js
More file actions
34 lines (33 loc) · 826 Bytes
/
Copy pathTrees.js
File metadata and controls
34 lines (33 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//code block for a tree node
function treeNode(value)
{
this.value = value;
this.children = []
}
//Binary tree node , it has only two child nodes
function binaryTreeNode(value)
{
this.value = value;
this.left = null ;
this.right = null;
}
//Binary tree always has a root node which is initialized to null befroe any elemnt is inserted
function binaryTree()
{
this._root = null;
}
// tree traversal - Pre-order traversal
binaryTree.prototype.traversePreOrder = function()
{
this.traversePreOrderHelper(this._root);
function traversalPreOrderHelper(node)
{
if(!node)
{
return;
console.log(node.value);
traversalPreOrderHelper(node.left);
traversePreOrderHelper(node.right);
}
}
}