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:
Samuel Facchinello
2024-06-13 21:00:16 +02:00
committed by GitHub
parent 51fcc66345
commit 87b17e0571
68 changed files with 629 additions and 261 deletions

View File

@@ -23,8 +23,9 @@ public class CircularQueue {
public boolean isFull() {
if (topOfQueue + 1 == beginningOfQueue) {
return true;
} else
} else {
return topOfQueue == size - 1 && beginningOfQueue == 0;
}
}
public void enQueue(int value) {

View File

@@ -125,9 +125,13 @@ public class LinkedQueue<T> implements Iterable<T> {
*/
public T peek(int pos) {
if (pos > size) throw new IndexOutOfBoundsException("Position %s out of range!".formatted(pos));
if (pos > size) {
throw new IndexOutOfBoundsException("Position %s out of range!".formatted(pos));
}
Node<T> node = front;
while (pos-- > 0) node = node.next;
while (pos-- > 0) {
node = node.next;
}
return node.data;
}
@@ -170,14 +174,18 @@ public class LinkedQueue<T> implements Iterable<T> {
* Clear all nodes in queue
*/
public void clear() {
while (size > 0) dequeue();
while (size > 0) {
dequeue();
}
}
@Override
public String toString() {
StringJoiner join = new StringJoiner(", "); // separator of ', '
Node<T> travel = front;
while ((travel = travel.next) != null) join.add(String.valueOf(travel.data));
while ((travel = travel.next) != null) {
join.add(String.valueOf(travel.data));
}
return '[' + join.toString() + ']';
}

View File

@@ -87,9 +87,13 @@ class PriorityQueue {
while (2 * pos <= nItems) {
int current = 2 * pos; // Jump to the positon of child node
// Compare both the children for the greater one
if (current < nItems && queueArray[current] < queueArray[current + 1]) current++;
if (current < nItems && queueArray[current] < queueArray[current + 1]) {
current++;
}
// If the parent node is greater, sink operation is complete. Break the loop
if (queueArray[pos] >= queueArray[current]) break;
if (queueArray[pos] >= queueArray[current]) {
break;
}
// If not exchange the value of parent with child
int temp = queueArray[pos];