Given an expression in infix form (operators appear inline in the expression) like 3 * (2 + 5) Evaluate the result i.e. 21 Hint: Transform it to its postfix equivalent 3 2 5 + * This form can be easily evaluated by a computer. You keep pushing terms onto a stack.. everytime you hit a operator, you pop the last 2 values and perform the operation, push the result back on the stack. In time, you will run out of terms and have the result at the top of the stack. e.g. Stack builds from left to right (TOS is extreme right) Read 3 Stack [3] Read 2 Stack [3 2] Read 5 Stack [3 2 5] Read + Stack [3 7] #Pop 5,2 Perform 2+5, Store 7 back on stack Read * Stack [21] # Pop 7,3 Perform 3*7, Store 21 back on stack. |