We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 30020fd commit bd0cfc2Copy full SHA for bd0cfc2
1 file changed
src/main/java/com/thealgorithms/datastructures/queues/ReverseQueueRecursion.java
@@ -8,7 +8,7 @@
8
public final class ReverseQueueRecursion {
9
10
private ReverseQueueRecursion() {
11
- // Private constructor to prevent instantiation
+ // private constructor to prevent instantiation
12
}
13
14
/**
@@ -18,14 +18,9 @@ private ReverseQueueRecursion() {
18
* @param <T> type of elements in the queue
19
*/
20
public static <T> void reverseQueue(final Queue<T> queue) {
21
- if (queue == null) {
+ if (queue == null || queue.isEmpty()) {
22
return;
23
24
-
25
- if (queue.isEmpty()) {
26
- return;
27
- }
28
29
final T front = queue.poll();
30
reverseQueue(queue);
31
queue.add(front);
0 commit comments