Presentation on theme: "Yinchong Han Linjia Jiang. Introduction There are three forms of expressions which are prefix, infix and postfix notation. The project will evaluate infix."— Presentation transcript:
Yinchong Han Linjia Jiang
Introduction There are three forms of expressions which are prefix, infix and postfix notation. The project will evaluate infix and postfix expressions then convert one to the other. Outline 1. Project Specification 2. Applications 3. Design & Testing 4. Conclusion
Expressions X = ((A/(B-C+D)) * (E-A) * C Made of operands, operators, and delimiters. Operands can be any legal variable name or constant. The values that variables take must be consistent with the operations performed on them. These operations are described by the operators. First, there are the basic arithmetic operators: plus, minus, times, and divide (+, −, *, /). Other arithmetic operators include unary minus, and %. A second class is the relational operators:, >=, and >. These are usually defined to work for arithmetic operands.
Priority of operators Within any pair of parentheses the operators have the highest priority. Priority of operators
Infix Notation X + Y Operators are written in-between their operands. A * ( B + C ) / D means: "First add B and C together, then multiply the result by A, then divide by D to give the final answer." Infix notation needs extra information to make the order of evaluation of the operators clear
Postfix Notation X Y + "Reverse Polish notation“ Operators are written after their operands. The infix expression given above ” A * ( B + C ) / D” is equivalent to A B C + * D / Order. Operators act on values immediately to the left of them. (A (B C +) *) D /)
Prefix Notation + X Y Prefix notation (also known as "Polish notation) Operators are written before their operands. The expression given above ” A * ( B + C ) / D” is equivalent to / * A + B C D Order. Operators act on the two nearest values on the right. /(* A (+ B C) ) D) Compare to Postfix Notation
Converting between Infix and Postfix InfixPostfix ( (A * B) + (C / D) )( (A B *) (C D /) +) ((A * (B + C) ) / D)( (A (B C +) *) D /) (A * (B + (C / D) ) )(A (B (C D /) +) *) It is simple to describe an algorithm for producing postfix from infix: 1.Fully parenthesize the expression. 2.Move all operators so that they replace their corresponding right parentheses. 3.Delete all parentheses.
Converting between Infix and Postfix For example, A/B − C + D *E − A *C, 1.Fully bracket the expression. 2. Move all operators so that they replace their corresponding right brackets. 3. Delete all brackets.
Converting between Infix and Prefix For example, since we want A + B *C to yield ABC * +
Advantages of using postfix notation Whilst postfix notation might look confusing to begin with, it has several important advantages: it is unambiguous it is more concise it fits naturally with a stack-based system
Design & Testing Run Program: Testing
Conclusion 1.We have understand the theory and basic concepts first. After researching on websites and reading the textbook, we totally understand the concepts and know how to code the program. 2.We are working on our program which can convert infix form and postfix form of expressions one another. 3.After the finishing of the program, we will complete a final report at the end of this semester.
References List 1. Horowitz, E., Sahni, S., & Mehta, D. (1995). Fundamentals of Data Structures in C++, 147-154. 2. Deitel, P., Deitel, H. (2008). Visual C#: How to Program.