Infix expression-to-suffix expression

Source: Internet
Author: User

Before writing should introduce a formidable Polish mathematician--jan Lukasiewicz (Rukasevichi), he thought of a kind of suffix expression that does not need parentheses, we in order to commemorate him, call it inverse Poland (Reverse Polish NOTATION,RPN) said.

We use the usual standard arithmetic expression, such as: + + (3-1) X3+10/2, called infix expression.

Put 9 3 1-3 * + 10 2/+ (here from the example of the infix expression on the previous line) this type of form that does not require parentheses is called a suffix expression, and is also a computational formula that the computer likes.

Conversion rules:

Each number and symbol of the infix expression is traversed from left to right, and if the number is output, it becomes part of the suffix expression, and if the symbol is the priority of the top symbol, the right parenthesis or precedence is lower than the top of the stack (multiplication precedence plus minus), the top element of the stack is sequentially out of the stack and the current symbol is Until the final output suffix expression.

Note: Left-to-right brackets are also added to the stack. Others follow the rules in and out of the stack.

The most important principle is the last-in-first-out of the stack, just the symbol as the element into the stack.

Written on December 24, 2014.

Infix expression-to-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.