Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <stack>
- using namespace std;
- int symb_priotiry(char symb)
- {
- switch (symb)
- {
- case '^':
- return 4;
- case '*':
- case '/':
- return 3;
- case '+':
- case '-':
- return 2;
- case ')':
- return 1;
- case '(':
- return 0;
- default:
- return -1;
- }
- }
- int main() {
- const int N = 10;
- stack<char> stk;
- int i,j=50, tos = 0;
- char* line = new char;
- char ch[50];
- char smb[50];
- int len = 0;
- cin >> ch[50];
- for (i = 0; i < 50; i++)
- if(ch[i] == '\0') j--;
- do
- {
- for (i = 0; i < j; i++)
- {
- if (ch[i] == '0' || ch[i] == '1' || ch[i] == '2' || ch[i] == '3' || ch[i] == '4' || ch[i] == '5' || ch[i] == '6' || ch[i] == '7' || ch[i] == '8' || ch[i] == '9') {
- line[i] = ch[i];
- len++;
- }
- else
- {
- smb[i] = ch[i];
- symb_priotiry(smb[i]);
- switch (smb[i])
- {
- case 0:
- stk.push(ch[i]);
- tos++;
- case 1:
- do {
- line[i] = stk.top();
- len++;
- stk.pop();
- tos--;
- } while (smb[i] != '0');
- stk.pop();
- tos--;
- case 2:
- case 3:
- case 4:
- if (stk.empty()) {
- stk.push(ch[i]);
- tos++;
- }
- else {
- if (smb[i] >= smb[i - 1]) {
- stk.push(ch[i]);
- tos++;
- }
- else {
- line[i] = stk.top();
- len++;
- stk.pop();
- tos--;
- }
- }
- }
- }
- }
- } while (ch[i] != '\0');
- cout << endl;
- for (i = 0; i < len; i++)
- {
- cout << line[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement