File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
src/main/java/com/thealgorithms/datastructures/queues Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change 88public 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 }
You can’t perform that action at this time.
0 commit comments