mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-23 20:44:39 +08:00
style: enable NeedBraces
in checkstyle (#5227)
* enable style NeedBraces * style: enable NeedBraces in checkstyle --------- Co-authored-by: Samuel Facchinello <samuel.facchinello@piksel.com>
This commit is contained in:

committed by
GitHub

parent
51fcc66345
commit
87b17e0571
@ -51,7 +51,9 @@ public final class NextSmallerElement {
|
||||
Arrays.fill(result, -1);
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
while (!stack.empty() && stack.peek() >= array[i]) stack.pop();
|
||||
while (!stack.empty() && stack.peek() >= array[i]) {
|
||||
stack.pop();
|
||||
}
|
||||
if (stack.empty()) {
|
||||
result[i] = -1;
|
||||
} else {
|
||||
|
@ -35,11 +35,17 @@ public final class PostfixToInfix {
|
||||
|
||||
public static boolean isValidPostfixExpression(String postfix) {
|
||||
/* Postfix expression length should NOT be less than 3 */
|
||||
if (postfix.length() < 3) return false;
|
||||
if (postfix.length() < 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* First two characters should NOT be operators */
|
||||
if (isOperator(postfix.charAt(0))) return false;
|
||||
if (isOperator(postfix.charAt(1))) return false;
|
||||
if (isOperator(postfix.charAt(0))) {
|
||||
return false;
|
||||
}
|
||||
if (isOperator(postfix.charAt(1))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int operandCount = 0;
|
||||
int operatorCount = 0;
|
||||
@ -51,14 +57,18 @@ public final class PostfixToInfix {
|
||||
|
||||
if (isOperator(token)) {
|
||||
operatorCount++;
|
||||
if (operatorCount >= operandCount) return false;
|
||||
if (operatorCount >= operandCount) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (operatorCount == 0) {
|
||||
operandCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (operandCount != operatorCount + 1) return false;
|
||||
if (operandCount != operatorCount + 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Operand count is set to 2 because:-
|
||||
*
|
||||
@ -80,7 +90,9 @@ public final class PostfixToInfix {
|
||||
public static String getPostfixToInfix(String postfix) {
|
||||
String infix = "";
|
||||
|
||||
if (postfix.isEmpty()) return infix;
|
||||
if (postfix.isEmpty()) {
|
||||
return infix;
|
||||
}
|
||||
|
||||
/* Validate Postfix expression before proceeding with the Infix conversion */
|
||||
if (!isValidPostfixExpression(postfix)) {
|
||||
|
Reference in New Issue
Block a user