| 10 | */ |
| 11 | |
| 12 | void rpn(string str, int n){ |
| 13 | stack<char>s; |
| 14 | for(int i=0;i<n;i++){ |
| 15 | if(str[i] == '('){ //Ignore opening brackets |
| 16 | continue; |
| 17 | } |
| 18 | else if(str[i]>='a' && str[i]<='z'){ |
| 19 | cout<<str[i]; //Print Operands |
| 20 | } |
| 21 | else if(str[i] == '+' || str[i] == '*' || str[i] == '-' || str[i] == '/' || str[i] == '^'){ |
| 22 | |
| 23 | |
| 24 | s.push(str[i]); //Store operators in stack |
| 25 | } |
| 26 | else if(str[i] == ')'){ |
| 27 | cout<<s.top(); //Print the top most operator from stack whenever closing brackets occur |
| 28 | s.pop(); //remove operators from stack. |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | int main() |
| 33 | { |
| 34 | jaadu; |