DSL Practical 7
DSL Practical 7
#include <stack>
#include <string>
#include <cctype>
#include <sstream>
using namespace std;
while (!s.empty()) {
postfix += s.top();
postfix += ’ ’;
s.pop();
}
return postfix;
}
switch (token[0]) {
case ’+’: s.push(operand1 + operand2); break;
case ’-’: s.push(operand1 - operand2); break;
case ’*’: s.push(operand1 * operand2); break;
case ’/’: s.push(operand1 / operand2); break;
}
}
}
return s.top();
}
int main() {
string infixExpression;
cout << "Enter infix expression: ";
getline(cin, infixExpression);
string postfixExpression = infixToPostfix(infixExpression);
cout << "Postfix expression: " << postfixExpression;
}
Output:
Enter infix expression: a+b*(c-d)
Postfix expression: a b c d - * +