Professional Documents
Culture Documents
Infix To Postfix Conversion
Infix To Postfix Conversion
#include <iostream>
#include <cstring>
bool isOperator(char c) {
switch(op) {
case '+':
case '-':
return 1;
case '*':
case '/':
return 2;
case '^':
return 3;
default:
return 0;
char c = expression[i];
if (isalnum(c)) {
postfix[j++] = c;
} else if (c == '(') {
stack[++top] = c;
} else if (c == ')') {
postfix[j++] = stack[top--];
} else if (isOperator(c)) {
postfix[j++] = stack[top--];
stack[++top] = c;
postfix[j++] = stack[top--];
int main() {
cin.getline(expression, 100);
infixToPostfix(expression, postfix);
cout << "The postfix expression is: " << postfix << endl;
return 0;