The first thing I would suggest is you parse the expression from a string (and not user input), and return an expression list (not void, and not in a global).
You can then test with
LinkedStack in2post( std::string expr );
int main ( ) {
std::string expr = "3+7-6/2*8+7=";
LinkedStack result = in2post( expr );
}
You can then expand the tests with
LinkedStack in2post( std::string expr );
int main ( ) {
std::string expr[] = {
"1=",
"1+2=",
"1+2*3",
"3+7-6/2*8+7=",
};
for ( int i = 0 ; i < sizeof expr / sizeof *expr ; i++ ) {
LinkedStack result = in2post( expr[i] );
}
}
When you're finally happy, then you can do
std::string myExpr;
getline( cin, myExpr );
LinkedStack result = in2post( myExpr );
As far as algorithms go, look up the "shunting yard algorithm".
Salem
Posting Sage
Team Colleague
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953