style: format code (#4212)

close #4204
This commit is contained in:
acbin
2023-06-09 18:52:05 +08:00
committed by GitHub
parent ad03086f54
commit 00282efd8b
521 changed files with 5233 additions and 7309 deletions

View File

@ -1,7 +1,7 @@
package com.thealgorithms.datastructures.queues;
//This program implements the concept of CircularQueue in Java
//Link to the concept: (https://en.wikipedia.org/wiki/Circular_buffer)
// This program implements the concept of CircularQueue in Java
// Link to the concept: (https://en.wikipedia.org/wiki/Circular_buffer)
public class CircularQueue {
int[] arr;
@ -23,7 +23,8 @@ public class CircularQueue {
public boolean isFull() {
if (topOfQueue + 1 == beginningOfQueue) {
return true;
} else return topOfQueue == size - 1 && beginningOfQueue == 0;
} else
return topOfQueue == size - 1 && beginningOfQueue == 0;
}
public void enQueue(int value) {

View File

@ -124,11 +124,9 @@ 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));
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;
}
@ -140,7 +138,6 @@ public class LinkedQueue<T> implements Iterable<T> {
@Override
public Iterator<T> iterator() {
return new Iterator<>() {
Node<T> node = front;
@Override
@ -168,16 +165,14 @@ 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

@ -1,8 +1,5 @@
package com.thealgorithms.datastructures.queues;
/**
* This class implements a PriorityQueue.
*
@ -126,7 +123,8 @@ class PriorityQueue {
if (isEmpty()) {
throw new RuntimeException("Queue is Empty");
} else {
int max = queueArray[1]; // By defintion of our max-heap, value at queueArray[1] pos is the greatest
int max = queueArray[1]; // By defintion of our max-heap, value at queueArray[1] pos is
// the greatest
// Swap max and last element
int temp = queueArray[1];
@ -175,4 +173,3 @@ class PriorityQueue {
return nItems;
}
}