public String createInfix(Expression root)
    {
        String str = "";
        String closeParen = "";
        String leftOpenParen = "";
        String leftCloseParen = "";

        if(root == null) {
            return str;
        }

        if (ExpressionParser.isOperand(root.getType(), var)) {
            str += root.getType();

        }
        else if(root.getType().equals("$")) {
            str += "-";
        }
        else if(ExpressionParser.isFunction(root.getType())) { // does not include unary minus
            str += root.getType();
            str += "(";
            closeParen = ")";
        }
        else { // is operator
            int parentPrecedence = ExpressionParser.getPrecedence(root.getType());

            str += root.getType();
            if(ExpressionParser.isOperator(root.getLeftChild().getType()) && (ExpressionParser.getPrecedence(root.getLeftChild().getType()) < parentPrecedence)) {
                leftOpenParen = "(";
                leftCloseParen = ")";
            }
			else if(ExpressionParser.isOperator(root.getRightChild().getType()) && (ExpressionParser.getPrecedence(root.getRightChild().getType()) < parentPrecedence)) {
					str += "(";
					closeParen = ")";

            }
        }

        return leftOpenParen + createInfix(root.getLeftChild()) + leftCloseParen + str + createInfix(root.getRightChild()) + closeParen;
    }
public String createInfix ( Expression root ) { String str = "" ; String closeParen = "" ; String leftOpenParen = "" ; String leftCloseParen = "" ; if ( root == null ) { return str ; } if ( ExpressionParser . isOperand ( root . getType ( ) , var ) ) { str += root . getType ( ) ; } else if ( root . getType ( ) . equals ( "$" ) ) { str += "-" ; } else if ( ExpressionParser . isFunction ( root . getType ( ) ) ) { str += root . getType ( ) ; str += "(" ; closeParen = ")" ; } else { int parentPrecedence = ExpressionParser . getPrecedence ( root . getType ( ) ) ; str += root . getType ( ) ; if ( ExpressionParser . isOperator ( root . getLeftChild ( ) . getType ( ) ) && ( ExpressionParser . getPrecedence ( root . getLeftChild ( ) . getType ( ) ) < parentPrecedence ) ) { leftOpenParen = "(" ; leftCloseParen = ")" ; } else if ( ExpressionParser . isOperator ( root . getRightChild ( ) . getType ( ) ) && ( ExpressionParser . getPrecedence ( root . getRightChild ( ) . getType ( ) ) < parentPrecedence ) ) { str += "(" ; closeParen = ")" ; } } return leftOpenParen + createInfix ( root . getLeftChild ( ) ) + leftCloseParen + str + createInfix ( root . getRightChild ( ) ) + closeParen ; }
creates string representing infix expression