Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double evalute() {
- OurStack<String> postFixStack = new OurStack<String>();
- while (!postFix.isEmpty())
- {
- curr = postFix.remove();
- if (!isoperand(curr)) {
- // curr is +, -, *, /
- double operand2 = postFixStack.pop();
- double operand1 = postFixStack.pop();
- if curr == "+"
- postFixStack.push(operand1 + operand2);
- else if curr == "-"
- postFixStack.push(operand1 - operand2);
- else if curr == "*"
- postFixStack.push(operand1 * operand2);
- else
- postFixStack.push(operand1 / operand2);
- } else {
- // curr is a number
- postFixStack.push(Double.parseDouble(curr));
- }
- }
- return postFixStack.peek(); // last number remaining on stack
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement