infix conversion to suffix (inverse polish) method

Source: Internet
Author: User

For the use of low-level programming language is to achieve the processing of expressions, suffix (inverse polish) is the most convenient. The following is an algorithm that converts infix (common expressions) to Postfix:
Stack bottom ' # ', read infix verbatim from left to right:
A. When the current character is a number, the output is direct;
B. When the current character is "(", the stack is pressed;
C. When the current character is "", The Top "(") in the stack pops up and outputs all the preceding operators, and then deletes the "(" in the stack;
D. When the current character is an operator, it pops up in the stack with precedence greater than or equal to the current operator (until before), output, and then stack the current operator;
E. When "#" is displayed, the content output from all stacks pops up

Infix type: A * (B+C)/d+e

Suffix type: abc+*d/e+

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.