Suppose that all the integer operands are stored in the stack S , and all the operators in the other stack S
. The function F() does the following operations sequentially:
(1) Pop two operands a and b from S1 ;
(2) Pop one operator op from S2 ;
(3) Calculate b op a; and
(4) Push the result back to S1
Now given { 5, 8, 3, 2 } in S1(where 2 is at the top), and { *, -, + } in S2 (where + is at the top). What is remained at the top of S1 after F() is executed 3 times?
这是两个栈,都pop访问top的。注意是b op a
因此
第一次:a=2,b=3, op= + ; 3 + 2 = 5
第二次:a=5,b=8,op=-; 8-5=3
第三次:a=3,b=5,op=, 53=15;
结果是15.