what i'm trying to do is convert a infix expression to a postfix expression using the std stack. for one of the cases (if the current character of the input string is an operator), i go to this function with the parameter being the operator:
s is the stack of type char. so i need to move through the stack to go implement the following logic:Code:void InfixToPostfix::operatorCase(char op) { string f; //assert(!s.empty()); assert(s.top() != NULL); for (int k = s.top(); (k != '(' || k != 0) && (precidence(k) >= precidence(s.top())); k--) //<--cant decrement like that { //cout << "yo"; s.push(op); f = s.top(); s.pop(); } postfix.append(f); }
if the scanned symbol is an operator:
* pop and append to the postfix expression every operator from the stack that is above the most recently scanned left parenthesis (or bottom of stack if no left parenthesis) and has precedence greater than or equal to the new operator.
* push the new operator onto the stack.
any ideas? thanks