Prefix infix suffix expression

Source: Internet
Author: User

1. The prefix expression is called the Polish style, the suffix is called the inverse Polish style

2. Infix expression to the other two more simple, pre-and post-prefix infix more troublesome

3. The problem is to evaluate the expression or evaluation, if the evaluation is required two stacks, one is the operation Fu Yi, one is the operand stack, and so on after the stack of operators stack up, and the operation of the stack top two operand calculation and will

Results re-pressed into the stack

4. Only infix expressions have parentheses to say that the Polish and inverse Polish operations are strictly defined and do not require parentheses

5. The computer does not have the ability to calculate infix, it needs to be converted to polish or inverse Polish style

6. Polish-style and inverse Polish-type programming problems have not yet seen, only to fill in the blanks, perhaps because the computer is more need is polish and reverse Polish style

7. How to turn the Infix method to reverse Poland:

             

Number encountered: Direct output
Encountered ' (': Press stack
Encountered ') ': continues out of the stack, if the sign out of the stack is not ' (' then output, otherwise terminate the stack.
When the symbol is encountered, the operation priority of the symbol and the top of the stack is determined, and if the operation priority of the top symbol is high, the stack is stacked and output until the priority is equal or the stack is empty, and if the operation priority of the top symbol is lower or equal to the operation priority of the current symbol, the current symbol is pressed.
After the string is processed, all the remaining symbols in the stack are output.

8. The method of converting infix to Polish style:

            

Conversion to prefix: from right to left to iterate infix expression, encountered operand, output, encountered operator, the current operator priority is greater than or equal to the top of the stack operator priority, into the stack, otherwise, pop-up stack top priority is greater than the current operator operator, The current operator is in the stack. Encountered ') ': Press stack
Encountered ' (': Persist out of the stack, if the sign out of the stack is not ') ' then output, otherwise terminate the stack. After the string is processed, all the remaining symbols in the stack are output.

            

Prefix infix suffix expression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.