Files
DEV/DEV3.2/arbre/infixe/OperatorNode.java

20 lines
659 B
Java
Raw Normal View History

2024-11-27 12:26:48 +01:00
// 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() + ")";
}
}