We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 51ef073 commit 9af8567Copy full SHA for 9af8567
src/main/java/com/thealgorithms/datastructures/queues/ReverseQueueRecursion.java
@@ -1,12 +1,26 @@
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
private ReverseQueueRecursion() {
10
+ // private constructor to prevent instantiation
11
}
12
13
+ /**
14
+ * Reverses the given queue recursively.
15
+ *
16
+ * @param queue the queue to reverse
17
+ * @param <T> the type of elements in the queue
18
19
public static <T> void reverseQueue(final Queue<T> queue) {
20
if (queue == null || queue.isEmpty()) {
21
return;
22
23
24
final T front = queue.poll();
25
reverseQueue(queue);
26
queue.add(front);
0 commit comments