0

Hey guys, I need to write a code to evaluate postfix expression. I started on it but now I'm stuck. Below I have what I started on and the file that it needs to go into. I need it to do the following:
If the token is an operator of two items are popped off the stack. the operator is applied to them
the result is pushed back onto the stack


So far I have

for (i=0; i < token; i++)
if (token[i] == integer)
{
Push(token[i];
}
else if (token[i] == '*; || token[i] == '+'|| token[i] == '/' || token[i] == '-')
{
stack = pop();
stack2 = pop();

switch(token[i])
{
case '+' : q= stack2 + stack break;
case '-' : q= stack2 - stack break;
case '*' : q= stack2 * stack break;
case '/' : q= stack2 / stack break;
}

Push (q);

z = Pop();
return z

Edited by react05: n/a

2
Contributors
1
Reply
4
Views
7 Years
Discussion Span
Last Post by WaltP
0

First things first -- format your code so we can follow what you are doing.

The concepts looks good except for the ';' on line 6.

I'd also change the names of stack and stack2 to value1 and value2

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.