[Post-order operation]: Operation
/* Description of post-order operations: the advantage of converting a middle-order to a post-order operation is that you do not have to deal with the suborder Problems of the operation, as long as the pre-order operation is followed by the Post-order operation. Solution: When an operation is performed, it is read from the front of the back-order type. When an operator is encountered, it is first saved to the stack. If an operator is encountered, two operators are taken out from the stack for calculation, then store the result back to the stack. If the operation is completed, the value at the top of the stack is the answer, for example, we calculate the formula 12 + 34 + * (that is, (1 + 2) * (3 + 4 )): read stack 1 12 12 + 33 33 (saved back after 1 + 2) 4 334 + 37 (stored back after 3 + 4) * 21 (stored back after 3*7) */# include <stdio. h> # include <stdlib. h> void evalPf (char *); double cal (double, char, double); int main (void) {char input [80]; printf ("input the postfix: "); scanf (" % s ", input); evalPf (input); return 0 ;}void evalPf (char * postfix) {double stack [80] ={ 0.0 }; char temp [2]; char token; int top = 0, I = 0; temp [1] = '\ 0'; while (1) {token = postfix [I]; switch (token) {case '\ 0': printf ("ans = % f \ n", stack [top]); return; case' + ': case '-': case '*': case '/': stack [top-1] = cal (stack [top], token, stack [top-1]); top --; break; default: if (top <sizeof (stack)/sizeof (float) {temp [0] = postfix [I]; top ++; stack [top] = atof (temp);} break;} I ++;} double cal (double p1, char op, double p2) {switch (op) {case '+': return p1 + p2; case '-': return p1-p2; case '*': return p1 * p2; case '/': return p1/p2 ;}}