Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void evaluateOperator(String operator){
- LinkedList<Double> result = new LinkedList<>();
- //Grabs the number of arguments the operator needs from the operatorMap
- for (int i = 0; i < operatorMap.get(operator).numArgs(); i++) {
- result.add(stack.pop());
- System.out.println(result.get(i));
- }
- stack.push(operatorMap.get(operator).eval(result));
- }
- public static class Add implements Operator {
- /**
- * @return
- */
- @Override
- public int numArgs() {
- return 2;
- }
- @Override
- public double eval(List<Double> args) {
- return args.get(0) + args.get(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment