fin arbre
This commit is contained in:
20
DEV3.2/arbre/infixe/OperatorNode.java
Normal file
20
DEV3.2/arbre/infixe/OperatorNode.java
Normal file
@@ -0,0 +1,20 @@
|
||||
// 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() + ")";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user