-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTRUCT_Tree.java
More file actions
42 lines (34 loc) · 924 Bytes
/
Copy pathSTRUCT_Tree.java
File metadata and controls
42 lines (34 loc) · 924 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
abstract class TreeNode {
abstract int getValue(); // 2 Nodes : operators and constants (leafs) so we have to make an abstract to not differentiate a constnode and operatornode
}
class ConstNode extends TreeNode {
private final int value;
public ConstNode(int value) {
this.value = value;
}
@Override
int getValue() {
return value;
}
}
abstract class OperatorNode extends TreeNode {
protected TreeNode left;
protected TreeNode middle;
protected TreeNode right;
public OperatorNode(TreeNode left, TreeNode middle, TreeNode right)
{
this.left = left;
this.middle = middle;
this.right = right;
}
public OperatorNode(TreeNode left, TreeNode right)
{
this(left, null, right);
}
public OperatorNode(TreeNode left)
{
this(left, null, null);
}
@Override
abstract int getValue();
}