Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stack>
- #include<iostream>
- #include<conio.h>
- using namespace std;
- int getPriority(char op)
- {
- switch (op)
- {
- case '(': return -1;
- case '*':
- case '/': return 1;
- case '+':
- case '-': return 2;
- }
- }
- template<class T>
- void printStack(stack<T> s)
- {
- stack<T> buf;
- while(s.size() != 0)
- {
- buf.push(s.top());
- s.pop();
- }
- while(buf.size() != 0)
- {
- cout << buf.top()<<" ";
- buf.pop();
- }
- cout << endl;
- }
- int main()
- {
- stack<char> znak;
- stack<int> nums;
- int a = 0;char ch;
- while((ch = getchar()) != '\n')
- {
- if(ch == '+' || ch == '-' || ch == '*' || ch == '/') znak.push(ch);
- else if(ch >= '0' && ch <='9')
- {
- a = a*10 + ch-'0';
- }
- else if(a != 0) {nums.push(a);a = 0;}
- }
- printStack(nums);
- printStack(znak);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement