Home » Stacks & Queues(Use Me !!) » Reverse Stack Inplace

Reverse Stack Inplace

import java.util.Stack;

public class ReverseStackInPlace {
Stack<Integer> s;
public void ReverseInPlaceStack() {
s = new Stack<Integer>();
 * call this function to reverse inplace stack

 public void reverseStack() {
if (!s.isEmpty()) {
int data = s.pop();
public void pushInStack(int a) {
if (s.isEmpty()) {

System.out.print(" "+s.push(a));
int b = s.pop();

 public static void main(String[] args) {

ReverseStackInPlace st = new ReverseStackInPlace();


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: