Question Arithmetic Expression Tree (AET) is a specific kind of a binary tree used to represent expressions.
Each node of a binary expression tree has zero or two children.
(/)
/ \
/ \
(*) (4)
/ \
/ \
(2) (+)
/ \
/ \
(3) (/)
/ \
/ \
(6) (2)
(/)
/ \
/ \
(8) (4)class Node {
int key;
Node left, right;
public Node (int key) {
this.key = key;
}
public abstract float evaluate();
}
class DivideNode extends Node {
public float evaluate() {
return this.left / this.right;
}
}
class AddNode extends Node {
public float evaluate() {
return this.left + this.right;
}
}
class ScalarNode extends Node {
public float evaluate() {
return key;
}
}