On 10 Jul 2004 16:35:07 -0700, Henry Jordon <bu*******@hotmail.com> wrote:

ok I have my problem entering in an expression in infix notation and

it outputs the postfix notation. I now need to evaluate the postfix

notation. I have some code written and there are comments as to what I

want to do but am unable to get it to work. So if someone could please

help me it would greatly be appreciated. Thanks for your help.

code:

void evaluates(char *infix)

{

Why infix? This function is supposed to be evaluating a postfix

expression. Are you confusing yourself or confusing us?

int position;

char symbol, numbers;

int number1, number2;

stack operator_stack;

for(position=0; infix[position] !='\0'; position++)

{

symbol=infix[position];

if(isoprand(symbol))

{

numbers=infix[position];

operator_stack.push(numbers);

}

else

{

//I want to get the top item from the stack_operator stack

and the next number and add them or subtract them and so on depending

on the sign. I'm not really sure what to do so if someone could please

help it would greatly be appreciated.

symbol=infix[position];

switch(symbol)

{

case '+':

break;

case '-':

break;

case '*':

break;

case '/':

break;

case '^':

break;

}

}

}

}

OK you are not using the algorithm I tried to explain the last time you

posted, so the above code is the wrong approach. You need a stack for

numbers, not a stack for operators.

Was there something about the method I gave that you didn't understand? Or

did you think it was wrong? Either way its best to respond, not just post

the same question again.

Here's the right way to do it (in pseudocode)

Stack number_stack;

for (all symbols in postfix expression)

{

if (symbol is a number)

{

number_stack.push(symbol);

}

else

{

number1 = number_stack.pop();

number2 = number_stack.pop();

if (symbol is +)

number3 = number1 + number2;

else if (symbol is -)

number3 = number1 - number2;

else

...

number_stack.push(number3);

}

}

answer = number_stack.pop();

john