We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 73b9cbc commit 4c8a782Copy full SHA for 4c8a782
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
/**
@@ -17,9 +17,16 @@ private ReverseQueueRecursion() {
17
* @param queue the queue to reverse
18
* @param <T> type of elements in the queue
19
*/
20
- public static <T> void reverseQueue(Queue<T> queue) {
21
- if (queue.isEmpty()) return;
22
- T front = queue.poll();
+ public static <T> void reverseQueue(final Queue<T> queue) {
+ if (queue == null) {
+ return;
23
+ }
24
+
25
+ if (queue.isEmpty()) {
26
27
28
29
+ final T front = queue.poll();
30
reverseQueue(queue);
31
queue.add(front);
32
0 commit comments