Reverse stack content only using push and pop

Reverse stack content only using push and pop

Given a stack how to reverse the contents of stacks using only stack operations (push and pop).

First we remove all items from stack and put it method stack, and then for each item from method stack, we’ll push to stack bottom.

Source Code:
Github: StackReverser.java

Output:

 
Before reverse: [50, 40, 30, 20, 10]
After reverse:[10, 20, 30, 40, 50]
Author: Hrishikesh Mishra