- #1
- 180
- 0
Homework Statement
Convert a postfix expression to the corresponding fully parenthesized infix expression...
Homework Equations
None.
The Attempt at a Solution
Code:
#include<iostream>
#include<cctype>
#include<string>
#include "MyStack.h"
#include "MyStack.cpp"
using namespace std;
void displayGreeting();
int main()
{
MyStack s1, temp;
string postfix, infix, tempstr;
char token;
displayGreeting();
cout << "Postfix expression: ";
getline(cin, postfix);
cout << "You entered: " << postfix << endl;
for (int i = 0; i < postfix.length(); i++)
{
token = postfix[i];
if (!isspace(token))
if(isdigit(token) || isalpha(token))
s1.push(token);
else if(token == '+' || '-' || '*' || '/')
temp.push(token);
}
s1.display(cout);
temp.display(cout);
return 0;
};
This is the code I have so far. I have two stacks
1) Stack s1, where it holds the digits or variables... such as a, b, 3...
2) Stack temp, where it holds the operands
I have a MyStack class, which is fine. I just need help developing an algorithm of converting something like this:
abc+* to (a*(b+c))... Any tips?