Infix expression-to-suffix expression

Source: Internet
Author: User

Infix expression---postfix expression

From left to right to iterate through the infix expression of each number and symbol, if the number is directly output, that is, as part of the suffix expression, if the symbol is divided into two cases, is the right parenthesis in the stack of left parenthesis (with the left parenthesis) of the elements out of the stack, not the right parenthesis to determine the precedence of the two, if the Then the stack top symbol element, which is not lower than the current symbol priority, is sequentially out of the stack and output, and the current symbol is then put into the stack until the infix expression is traversed.

Suffix expression calculation result

From left to right to iterate through each number and symbol in the expression, encountered the number on the stack, encountered the symbol will be at the top of the stack of two numbers out of the stack, the operation, the results into the stack, until the final results obtained

9 + (3-1) * 3 + 10/2 9 3 1-3 * + 10 2/+

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.