http://www.itint5.com/oj/#26 Evaluate an arithmetic expression. For simplicity, the following assumptions are made: There are only positive integers. There is no overflow. Only plus, minus, and multiply operations are supported. No parenthesis, divide, and modulo. All inputs are valid arithmetic expressions. Example: Input: 1+4*3-5 Output: 8 Input: 2-3-5*2 Output: -11 Note that multiplication has higher priority than plus and minus. Every time we meet a '*' , we will calculate the number. If we meet a '+' or '-' , we will call the recursion, or push the number into a data structure. Recursive version: Note that for minus operations, instead of using prevNum - calc(expr, currNum, pos) , we need to convert it to negative number (i.e., prevNum + calc(expr, -currNum, pos) ). Otherwise the result will be incorrect. For example, 5-4+2 , if we use the first approach, the result will be 5-(4+2)=-1 . However, it should be 5+(-4+2)=3 . Iterative v