Need urgent help on RPN

i am doing algorithm to evaluate postfix expression
class Stack{
public:
	Stack();
	Stack(const Stack &tokken); 
private:
	stack <char> mystack;
	char c;
	int i = c - '0'; 

};
Stack()
{
//what do I put here ?
}


second question
Get the nxt token (const, varaible, arthmetic operator)in the postfix
expression.
What is this mean ?
Third question
if the token is an operand, push it onto the stack. If it is an operator, then do the foloowing:
i. pop the top two values from the stack (if the stack does not contain two items, an error due to a malformed postfix expression has occured and evalutation terminated)
ii. Apply the operator to these two values
iii. Push the resulting value back onto the stack.
iii. return value.

so... for the third one
1
2
3
4
5
6
7
8
9
10
 if(isdigit(somevalue[i]))
       { i = somevalue.back();          
         somevalue.pop_back();
         x = somevalue.back();          
         somevalue.pop_back();
       }
          swtich(s[i])
         {
             case'+': a = i + x; break;?
          }


If you can answer at least one plz answer any one of my question Thank You !
Last edited on
1
2
3
4
Stack()
{
//what do I put here ?
}
Suppose that you do Stack foo; ¿how should be the internal state of `foo' after that point?
At least you should initialize your members (`c' is uninitalized, so `i' will hold garbage too).

>> Get the nxt token (const, varaible, arthmetic operator)in the postfix expression.
> What is this mean ?
Read the next character in the input. Classify it an threat it according.


> if the token is an operand, push it onto the stack. If it is an operator, then do the foloowing:
1
2
3
4
5
6
if( is_operand(token) )
   stack.push(token);
else if( is_opeator(token) ){
  //...
}
else //¿can this happen? 



1
2
 if(isdigit(somevalue[i]))
       { i = somevalue.back();
`i' is used as an index, but it seems that the container also stores indexes (doubt that, it stores operands)
There is no need to use one variable for everything, you may easily create another. Also, use meaningful names.
Last edited on
Topic archived. No new replies allowed.