Public feed
#602112
public interface ExpressionTreeInterface{ // post: returns true if this is a term (leaf); false otherwise. public boolean isTerm(); // pre: op is one of {'+', '-', '*', '/'}; b is not null // post: returns an expression tree representing (this op b) public ExpressionTreeInterface combine(char op, ExpressionTreeInterface b); // post: returns the number of terms (leaves) in this public int numTerms(); // post: returns a String representing this. Each subexpression // (an operator together with its children) must be enclosed // in parentheses. public String toString(); // post: returns a string representing the expression in RPN notation. public String toRPN(); // pre: All subtrees of this have the same implementation. // post: returns a list including all of the operators in this // The operators will be in the list in the same order as they // would appear in an in-fix expression. That is, the expression // tree corresponding to (3 + 5) * 12 would have the operators // listed as <+ *> and not <* +> public SubListInterface listOfOperators(); // pre: no subexpression in this results in a division by zero // post: returns the result of evaluating this. public int evaluate(); // pre: n != 0 // post: returns a new expression tree which is the same as this except // that every term t = i*n such that i is an integer larger than 1 // is replaced by the expression (i * n). public ExpressionTreeInterface factorBy(int n);}