Skip to content

Commit 4c8a782

Browse files
Update ReverseQueueRecursion.java
1 parent 73b9cbc commit 4c8a782

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/main/java/com/thealgorithms/datastructures/queues/ReverseQueueRecursion.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public final class ReverseQueueRecursion {
99

1010
private ReverseQueueRecursion() {
11-
// private constructor to prevent instantiation
11+
// Private constructor to prevent instantiation
1212
}
1313

1414
/**
@@ -17,9 +17,16 @@ private ReverseQueueRecursion() {
1717
* @param queue the queue to reverse
1818
* @param <T> type of elements in the queue
1919
*/
20-
public static <T> void reverseQueue(Queue<T> queue) {
21-
if (queue.isEmpty()) return;
22-
T front = queue.poll();
20+
public static <T> void reverseQueue(final Queue<T> queue) {
21+
if (queue == null) {
22+
return;
23+
}
24+
25+
if (queue.isEmpty()) {
26+
return;
27+
}
28+
29+
final T front = queue.poll();
2330
reverseQueue(queue);
2431
queue.add(front);
2532
}

0 commit comments

Comments
 (0)