77/**
88 * Utility class for evaluating postfix expressions using integer arithmetic.
99 * <p>
10- * Postfix notation, also known as Reverse Polish Notation (RPN), is a mathematical notation in which operators follow their operands.
11- * This class provides a method to evaluate expressions written in postfix notation.
10+ * Postfix notation, also known as Reverse Polish Notation (RPN), is a
11+ * mathematical notation in which operators follow their operands.
12+ * This class provides a method to evaluate expressions written in postfix
13+ * notation.
1214 * </p>
1315 * <p>
1416 * For more information on postfix notation, refer to
15- * <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation">Reverse Polish Notation (RPN) on Wikipedia</a>.
17+ * <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation">Reverse
18+ * Polish Notation (RPN) on Wikipedia</a>.
1619 * </p>
1720 */
1821public final class StackPostfixNotation {
@@ -22,16 +25,16 @@ private StackPostfixNotation() {
2225 private static BiFunction <Integer , Integer , Integer > getOperator (final String operationSymbol ) {
2326 // note the order of operands
2427 switch (operationSymbol ) {
25- case "+" :
26- return (a , b ) -> b + a ;
27- case "-" :
28- return (a , b ) -> b - a ;
29- case "*" :
30- return (a , b ) -> b * a ;
31- case "/" :
32- return (a , b ) -> b / a ;
33- default :
34- throw new IllegalArgumentException ("exp contains an unknown operation." );
28+ case "+" :
29+ return (a , b ) -> b + a ;
30+ case "-" :
31+ return (a , b ) -> b - a ;
32+ case "*" :
33+ return (a , b ) -> b * a ;
34+ case "/" :
35+ return (a , b ) -> b / a ;
36+ default :
37+ throw new IllegalArgumentException ("exp contains an unknown operation." );
3538 }
3639 }
3740
@@ -77,4 +80,4 @@ public static int postfixEvaluate(final String exp) {
7780 throw new IllegalArgumentException ("exp is not a proper postfix expression." );
7881}
7982return s .pop (); }
80- }
83+ } ̰
0 commit comments