mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +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
@@ -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) {
|
||||
|
||||
@@ -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() + ']';
|
||||
}
|
||||
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user