Advertisement
carlos1993

calc

Nov 6th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1.     double resolve(double op, double a, double b) {
  2.         char s = static_cast<char> (op);
  3.         switch (s) {
  4.             case '+': return a + b;
  5.             case '-': return a - b;
  6.             case '/': return a / b;
  7.             case '*': return a * b;
  8.             case '^': return pow(a,b);
  9.         }
  10.     }
  11.  
  12.     double result() {
  13.         stackClass s;
  14.         double a, b;
  15.         node tmp, r;
  16.         while (!postfix.empty()) {
  17.             tmp = postfix.pop();
  18.             if (tmp.isOperator()) {
  19.                 b = s.pop().data;
  20.                 a = s.pop().data;
  21.                 r = node(resolve(tmp.data, a, b));
  22.                 s.push(r);
  23.             } else {
  24.                 s.push(tmp);
  25.             }
  26.         }
  27.         return s.pop().data;
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement