A simple technique for converting infix expressions and pre-and suffix expressions [go]

Source: Internet
Author: User

35,15,+,80,70,-, *,20,/                      //Suffix expression (((35+15) * (80-70)/20) =25//                 infix expression  /,*,+,35,15,-, 80, 70, 20                   

  

The way people think is easy to fix ~~! Just as used to pull 10 into the system. Just about 2,3,4,8, and so on. ~~!

The way people are used to arithmetic is infix expression. And hit the prefix, suffix way: Confusion is just a way of expressing a formula (not the way you get used to)

I'm here to teach you a way that maybe your teacher didn't tell you. Simple conversion

A method of converting an infix to other formulas

Here I give an infix expression

a+b*c-(d+e)    //infix expression

  

First step: Add parentheses to all units of operation by the operator's precedence

The formula becomes:(A + (b*c))-(d+e))
Step Two:conversion prefix and suffix expressions
Prefix: Move the operation symbol before the corresponding parenthesis
It becomes:-(+ (A * (BC)) + (DE))
Remove the brackets:-+a*bc+de prefixes appear
Suffix: Move the operation symbol after the corresponding parenthesis
It becomes:((A (BC) *) + (DE) +)-
Remove the brackets: theabc*+de+- suffix appears
Found no, prefix, suffix is not required to use parentheses to determine the priority.

If you're used to pulling his algorithm. It is calculated from the front of both operands
Or find the operator later. Instead of looking in the middle, then you can just mental arithmetic pull.

Go to network ...

This article link: http://www.cnblogs.com/Hslim/p/5008460.html

Infix expressions and pre-and suffix expressions convert simple tricks [go]

Related Article

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.