private void evaluateStack() { if (stack.isNull()) throw new IllegalArgumentException("stack"); Stack thisStack = stack; int total = 0; while (thisStack != null) { String val = thisStack.pop(); if (val.equals("+")) { String int1 = thisStack.pop(); String int2 = thisStack.pop(); total = Integer.parseInt(int1) + Integer.parseInt(int2); thisStack.push(Integer.toString(total)); } else if (val.equals("s")) { String int1 = thisStack.pop(); String int2 = thisStack.pop(); thisStack.push(int1); thisStack.push(int2); } } }
private void displayStack() { if (stack.isNull()) throw new IllegalArgumentException(); Stack thisStack = stack; while (thisStack != null) { System.out.println(thisStack.peek()); thisStack = thisStack.tail(); } }