We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent dad4c69 commit 727769cCopy full SHA for 727769c
Misc/ReverseStackUsingRecursion.java
@@ -1,4 +1,4 @@
1
-package stacks_and_queues;
+/* Program to reverse a Stack using Recursion*/
2
3
4
import java.util.Stack;
@@ -38,7 +38,7 @@ public static void main(String[] args) {
38
39
//Function Used to reverse Stack Using Recursion
40
private static void reverseUsingRecursion(Stack<Integer> stack) {
41
- if(stack.isEmpty())
+ if(stack.isEmpty()) // If stack is empty then return
42
{
43
return;
44
}
@@ -60,7 +60,7 @@ private static void insertAtEnd(int temptop) {
60
int temp = stack.peek(); /* All the items are stored in call stack until we reach end*/
61
stack.pop();
62
63
- insertAtEnd(temptop);
+ insertAtEnd(temptop); //Recursive call
64
65
stack.push(temp);
66
0 commit comments