我遇到了方程求解器的一部分问题。我有一个包含后缀方程的对象数组,并且此方法评估每个值。
我遇到的问题是它崩溃告诉我列表为空(此时:double num1 = ((double)operandStack.pop());)
有人可以告诉我我在这里做错了什么吗?
DSAQueue<Object> postfixQueue = new DSAQueue<Object>();
.
.
.
.
private double evaluatePostfix (Queue<Object> postfixQueue)
{
DSAStack<Double> operandStack = new Stack<Double>();
while (postfixQueue.isEmpty() == false)
{
if (postfixQueue.peek() instanceof Double)
{
operandStack.push((Double)(postfixQueue.dequeue()));
}
else
{
double num1 = ((double)operandStack.pop());
double num2 = ((double)operandStack.pop());
char operator = ((char)postfixQueue.dequeue());
double result = executeOperation (operator, num1, num2);
operandStack.push(result);
}
}
double solution = operandStack.top();
return solution;
}