什么是前缀表达式(国外英文资料).docVIP

  • 9
  • 0
  • 约3.88万字
  • 约 11页
  • 2017-06-08 发布于河南
  • 举报
什么是前缀表达式(国外英文资料)

什么是前缀表达式(国外英文资料) What is a prefix expression Prefix expression is the arithmetic expression without parentheses, and it was written in front, and the operator operation number written on the back of the expression, also known as the polish. For example, minus 1 plus 2, 3, thats the same thing as 1 minus 2 plus 3. Edit this section How does the prefix expression evaluate For a prefix expression is evaluated, the first expression to scan from right to left, start from the first character on the right judgment, if the current character is a number until the Numbers at the end of the recording again, if it is operator, is the right of the nearest two Numbers corresponding operation, as a new Numbers and recorded. Its always going to be scanning to the left end of the expression, and its going to be the value of the expression. Prefix expression, for example, 1 + 2, 3, scanning to 3, record the number series, scan to 2, record the Numbers, when scanning to + the + moves to the right to do the operator between two Numbers, the record of 2 + 3, the result is 5, record the new Numbers, and continue to scan, scan to 1, record the number series, scan to - to - moves to the right to do the operator between two Numbers, for 1 to 5, the results for 4, so the value of the expression is - 4. Edit this section What is the use of a prefix expression The prefix expression is a very useful expressions, it can convert infix expression to rely on the simple operation can get result expression. For example, (a + b) * (c + d) translates to *, +, a, b, +, c, d. The advantage of this is that you can solve any of the infix expressions using only two simple operations. The method is: if the current character (or string) is numeric or variable, it is pressed into the stack. If the operator is an operator, the stack is pushed out of the top two elements of the stack and then pressed into the stack. When the prefix expression scan is over, the final result of the infix expression operation is i

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档