We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e8e5fc3 commit f34439dCopy full SHA for f34439d
src/main/java/com/thealgorithms/datastructures/queues/ReverseQueueRecursion.java
@@ -1,27 +1,12 @@
1
package com.thealgorithms.datastructures.queues;
2
-
3
import java.util.Queue;
4
5
-/**
6
- * Reverse a queue using recursion.
7
- */
8
public final class ReverseQueueRecursion {
9
10
private ReverseQueueRecursion() {
11
- // private constructor to prevent instantiation
12
}
13
14
- /**
15
- * Reverses the given queue recursively.
16
- *
17
- * @param queue the queue to reverse
18
- * @param <T> the type of elements in the queue
19
20
public static <T> void reverseQueue(final Queue<T> queue) {
21
if (queue == null || queue.isEmpty()) {
22
return;
23
24
25
final T front = queue.poll();
26
reverseQueue(queue);
27
queue.add(front);
0 commit comments