Q2 - constants), and the operators +, -, * and /, as well...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Question 2. Infix to Postfix In infix notation, a binary mathematical operator is placed between its operands (e.g., x + y), and brackets are used to change the default order of operations (e.g., z * (x + y)). In postfix notation, the operator is placed after the operands (e.g., x y +), and no brackets are needed (e.g., z x y + *). The class Expression allows an expression to be input as a string in infix notation, and provides a method, postfix, which converts the expression to postfix notation. The interface for postfix is provided: your job is to implement it. Your implementation need only support operands that are one-character lower-case letters (no numeric
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: constants), and the operators +, -, * and /, as well as round brackets ( and ). Spaces between characters in the infix expression should be ignored. Any other symbol should generate an InvalidInfixExpressionStringException . Note that the class expression does not verify that the string provided to the constructor is in valid infix notation. Your method postfix does not have to detect invalid infix expression strings: you can assume the expressions are valid. Here is a test program testExpression that provides a few test cases. You should, however, test your program using a broader range of test cases. Pay particular attention to boundary conditions....
View Full Document

This note was uploaded on 10/28/2010 for the course CSE 2011 taught by Professor Someone during the Summer '10 term at York University.

Ask a homework question - tutors are online