Your task in this week is to convert an infix expression to postfix expression. See the code template and sample output given billow for a clear understanding.
Also, write a function to evaluate a postfix expression.
Please do Comment the steps for understanding. Thanks.
Code template:
#include <iostream>
#include <sstream>
using namespace std;
/// implement your 'stack' here
int main()
{
Stack s;
string infix, postfix[100];
cout << "\t\tInfix to Postfix Converter v1.0\n";
cout << "\t\t===============================\n\n";
cout << "Enter an infix expression: ";
getline(cin, infix);
infix += " )";
s.push("(");
istringstream token(infix);
string t, p;
int i=0, j;
while(token>>t)
{
/// You have got the input symbol 't'.
/// Now you have to process all the input symbols and
/// fill in the 'postfix' array accordingly.
}
cout << endl << "The equivalent postfix expression is: ";
for(j=0; j<i; j++) cout << postfix[j] << " ";
cout << endl << endl;
return 0;
}
Sample output:
Infix to Postfix Converter v1.0
===============================
Enter an infix expression:A + ( B * C - ( D / E ^ F ) * G ) * H
The equivalent postfix expression is: A B C * D E F ^ / G * - H * +
Process returned 0 (0x0)execution time : 11.891 s
Press any key to continue.
Comments
Leave a comment