On the front, middle, postfix expression

On the front, middle, postfix expression

Before, during and postfix Olympiad in Informatics is relatively tasteless knowledge points. But knowledge within the scope of the syllabus, and turn postfix infix expression is more useful knowledge. So here is a brief introduction about.

Before former self, in postfix expression, I found many online blog and explain the ideas are not very clear, the novice or just not very friendly, thanks to explain @JZYShurak, let me build this thing an intuitive understanding. So I'll make up a basis for comparison, is better understood, more concise language blog. We are hoping to help the little chiefs from various quarters.


Infix expression

Infix expression is a common expression in our life, simply, it is that one can count expression . However, the computer Suan Bule. . (Computer Suan Bule said here is not to say that things can not be considered a computer, but the computer can be considered an expression of people's time to count not think like us).

example:

\(6\times 12+9-14\)

(PS unimportant nonsense: a few figures above has some special significance for bloggers (squinting smile))


Postfix expression

Why not "pre - in - after" The order of presentation of it? Since infix expression is most easily understood "above the third grade level will be able to understand." And understanding the operation process directed to the postfix expression is a data structure: the stack.

If you're not familiar with or do not understand the stack, on your own tutorial, which should be the most basic computer science data structure of.

Also take the example above:

\(6\times 12+9-14\)

Postfix expression is the process to achieve this:

First, build a memory stack operation symbol, a digital memory stack.

Then, across a symbol, the symbol stack on the pressure, it is pressed into digital numbers encountered the stack, if there are two stacks of digital numbers, a symbol from the symbol will pop up to the stack calculates these two numbers, push the result back to a number stack, and so on.

For example, the above equation can be written as a suffix expression:

\(\times 6 + 12 \quad 9 - 14\)

Obviously, for a certain infix expression, its corresponding postfix expression is not unique.


Prefix expression

The principle prefix and postfix expressions of similar expression, but only caveat is that the prefix expression is from the back turn! !

That is, the above example \ (6 \ times 12 + 9-14 \) may be converted into the following prefix expression:

\(14-9 \quad 12+6\times\)

Guess you like

Origin www.cnblogs.com/fusiwei/p/11615499.html