Sorry I posted it by mistake before I could ask my question. When I build it comes up fine however when I attempt to debug it the error "deque iterator not deferencable" keeps appearing. I've tried looking this up but can't find anything conclusive as to why this issue is occurring. Help would be much appreciated.

Also I'm not sure why it appears that way in the code I posted, but everywhere it says
exp<b></b>ression is meant to be the variable string expression.

Re: Evaluating a postfix expression

Posted 18 July 2012 - 03:14 PM

Have you stepped through your program with a debugger? If not, I think that you will find lines 34-49 very interesting when the user follows your instruction of using a space to separate digits or operators.

In this case, I don't think it's user error.

Also ending the expression with "" seems to conflict with your while loop condition.

Re: Evaluating a postfix expression

Posted 18 July 2012 - 03:26 PM

I'm not sure I understand how to fix the issue. This is an assignment I have to complete and I've been instructed to place spaces between all the inputted numbers and operators and to place a : at the end of the expression.

How would I go about altering the program to allow this?

jimblumberg, on 18 July 2012 - 03:21 PM, said:

Quote

exp<b></b>ression is meant to be the variable string expression.

This is a problem with the board software but thanks for catching the problem.

What compiler are you using?

Please show an complete example of your input.

It looks like you are trying to pop something off an empty stack.

Jim

I am using Visual Studio C++ 2010 Express. An example input given to me is as follows:

You must skip over the logic in the for loop if spaces are encountered.

Check to see if there are enough elements in the stack before doing each operation. If there are not, the expression is invalid. Once the loop is finished the stack should only contain one value. If it does not the expression was invalid.

Re: Evaluating a postfix expression

This is an assignment I have to complete and I've been instructed to place spaces between all the inputted numbers and operators and to place a : at the end of the expression.

If the ':' is the expression terminator, why are you looking for '=' on line 24? Is this code you got somewhere else? It's okay, we won't tell your teacher.

Quote

I'm not sure I understand how to fix the issue.

Well right now your code logic looks like:

while(input is not '=')
{
if input is a digit
handle digit
else
handle operator
}

Your else clause is a catch all for everything that is not a digit. And your handle operator code assumes that it will get an operator so it preemptively pops things off the stack, but never puts it back in if it wasn't an operator.