20 lines
659 B
Java
20 lines
659 B
Java
// Nœud opérateur
|
|
public class OperatorNode extends Node {
|
|
String operator;
|
|
Node left, right;
|
|
|
|
OperatorNode(String operator, Node left, Node right) {
|
|
this.operator = operator;
|
|
this.left = left;
|
|
this.right = right;
|
|
}
|
|
|
|
@Override
|
|
public String toInfix() {
|
|
// On ajoute systématiquement des parenthèses autour de chaque opération
|
|
if (operator == "*"){
|
|
return "(" + left.toInfix() + " x " + right.toInfix() + ")";
|
|
}
|
|
return "(" + left.toInfix() + " " + operator + " " + right.toInfix() + ")";
|
|
}
|
|
} |