-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10-tree-traversal.js
More file actions
40 lines (37 loc) · 895 Bytes
/
Copy path10-tree-traversal.js
File metadata and controls
40 lines (37 loc) · 895 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
35
36
37
38
39
40
class Node {
constructor(value){
this.data = value
this.left = null
this.right = null
}
preOrder(root){
if(root !== null){
console.log( root.data , " ")
this.preOrder(root.left)
this.preOrder(root.right)
}
}
InOrder(root){
if(root !== null){
this.InOrder(root.left)
console.log( root.data , " ")
this.InOrder(root.right)
}
}
postOrder(root){
if(root !== null){
this.postOrder(root.left)
this.postOrder(root.right)
console.log( root.data , " ")
}
}
}
let root = new Node(1)
root.left = new Node(3)
root.right = new Node(5)
root.left.left = new Node(2)
root.left.right = new Node(4)
root.right.right = new Node(8)
// root.postOrder(root)
// root.preOrder(root)
root.InOrder(root)