A detailed explanation of the stack (stack) implementation of the infix expression calculator-expression 3*2^(4+2*2-6*3)-5 evaluation process

When the expression 3*2^(4+2*2-6*3)-5 is evaluated in the evaluation process, when the scan reaches 6, the object stack and the operator stack are respectively (D), where ^ means exponentiation.

Answer: Object stack: 3,2,8  Operator stack: *,^,(,-

Analysis:

Object stack: 3, 2, 8; operator stack: *, ^, (, -.

The text indicates the specific process:

The first time: object stack: 3; operator stack: *;

Second time: Object stack: 3, 2; Operator stack: *, ^, (;

The third time: object stack: 3, 2, 4; operator stack: *, ^, (, +;

Fourth time: Object stack: 3, 2, 4, 2; Operator stack: *, ^, (, +, *;

Fifth time: Object stack: 3, 2, 4, 4; Operator stack: *, ^, (, +;

The sixth time (scan to 6): Object stack: 3, 2, 8; Operator stack: *, ^, (,-

The table shows the specific process:

Guess you like

Origin blog.csdn.net/weixin_41987016/article/details/108937602