Skip to content

Commit

Permalink
Reverse Stack
Browse files Browse the repository at this point in the history
  • Loading branch information
shivajipotnuru committed Jun 19, 2020
1 parent 2ba04a4 commit 2956982
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Stacks/Reverse Stack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Stack;

public class Solution {
public static void helper(Stack<Integer> s1,Stack<Integer> s2)
{
if(s1.isEmpty())
return;
int temp=s1.pop();
helper(s1,s2);
s2.push(temp);
}
public static void reverseStack(Stack<Integer> s1, Stack<Integer> s2) {
helper(s1,s2);
while(!s2.isEmpty())
s1.push(s2.pop());
}
}

0 comments on commit 2956982

Please sign in to comment.