File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
src/main/java/com/thealgorithms/stacks Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -41,10 +41,24 @@ public static int evaluatePostfix(String expression) {
41
41
return stack .pop ();
42
42
}
43
43
44
+ /**
45
+ * Checks if the given token is an operator.
46
+ *
47
+ * @param token The token to check.
48
+ * @return true if the token is an operator, false otherwise.
49
+ */
44
50
private static boolean isOperator (String token ) {
45
51
return token .equals ("+" ) || token .equals ("-" ) || token .equals ("*" ) || token .equals ("/" );
46
52
}
47
53
54
+ /**
55
+ * Applies the given operator to the two operands.
56
+ *
57
+ * @param operator The operator to apply.
58
+ * @param a The first operand.
59
+ * @param b The second operand.
60
+ * @return The result of applying the operator to the operands.
61
+ */
48
62
private static int applyOperator (String operator , int a , int b ) {
49
63
return switch (operator ) {
50
64
case "+" -> a + b ;
You can’t perform that action at this time.
0 commit comments