How do you not pop from an empty stack?
Sep 4, 2013 at 9:44pm UTC
Solved! Thanks!
Last edited on Sep 4, 2013 at 11:32pm UTC
Sep 4, 2013 at 10:15pm UTC
Your compute() assumes (lines 74-78) that the stack has at least two values in it. Either the caller (i.e. main) must ensure that this is true, and/or the function has to check it self.
Sep 4, 2013 at 10:20pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
void compute(const string& variable, stack<double >& rpnStack)
{
double left, right, result;
if ( !rpnStack.empty() )
{
right = rpnStack.top();
rpnStack.pop();
}
else
{
// stack is empty
// report error
}
if ( !rpnStack.empty() )
{
left = rpnStack.top();
rpnStack.pop();
}
else
{
// stack is empty
// report error
}
// ...
Topic archived. No new replies allowed.