forked from MaJesTySA/CodingInterviewJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryTreeNode.java
More file actions
42 lines (37 loc) · 954 Bytes
/
BinaryTreeNode.java
File metadata and controls
42 lines (37 loc) · 954 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
41
42
package utils;
public class BinaryTreeNode {
public int value;
public BinaryTreeNode left;
public BinaryTreeNode right;
public BinaryTreeNode parent;
public BinaryTreeNode(int value) {
this.value = value;
}
public void preOrder() {
System.out.print(this.value + "->");
if (this.left != null) {
this.left.preOrder();
}
if (this.right != null) {
this.right.preOrder();
}
}
public void inOrder() {
if (this.left != null) {
this.left.inOrder();
}
System.out.print(this.value + "->");
if (this.right != null) {
this.right.inOrder();
}
}
public void postOrder() {
if (this.left != null) {
this.left.postOrder();
}
if (this.right != null) {
this.right.postOrder();
}
System.out.print(this.value + "->");
}
}